diff --git a/doc/api/dns.markdown b/doc/api/dns.markdown index a30af870e5710a..d8ed53e3fa0f79 100644 --- a/doc/api/dns.markdown +++ b/doc/api/dns.markdown @@ -267,8 +267,9 @@ The following flags can be passed as hints to `dns.lookup`. of addresses supported by the current system. For example, IPv4 addresses are only returned if the current system has at least one IPv4 address configured. Loopback addresses are not considered. -- `dns.V4MAPPED`: If the IPv6 family was specified, but no IPv6 addresses -were found, then return IPv4 mapped IPv6 addresses. +- `dns.V4MAPPED`: If the IPv6 family was specified, but no IPv6 addresses were +found, then return IPv4 mapped IPv6 addresses. Note that it is not supported +on some operating systems (e.g FreeBSD 10.1). ## Implementation considerations diff --git a/lib/net.js b/lib/net.js index 76890335c1861a..99027638321841 100644 --- a/lib/net.js +++ b/lib/net.js @@ -926,8 +926,16 @@ function lookupAndConnect(self, options) { hints: 0 }; - if (dnsopts.family !== 4 && dnsopts.family !== 6) - dnsopts.hints = dns.ADDRCONFIG | dns.V4MAPPED; + if (dnsopts.family !== 4 && dnsopts.family !== 6) { + dnsopts.hints = dns.ADDRCONFIG; + // The AI_V4MAPPED hint is not supported on FreeBSD, and getaddrinfo + // returns EAI_BADFLAGS. However, it seems to be supported on most other + // systems. See + // http://lists.freebsd.org/pipermail/freebsd-bugs/2008-February/028260.html + // for more information on the lack of support for FreeBSD. + if (process.platform !== 'freebsd') + dnsopts.hints |= dns.V4MAPPED; + } debug('connect: find host ' + host); debug('connect: dns options ' + dnsopts);