summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Gilli <julien.gilli@joyent.com>2015-03-02 15:50:25 -0800
committerJulien Gilli <julien.gilli@joyent.com>2015-04-28 16:26:26 -0700
commit0e392f3b68fecf8d45032a8f427e22f7f1cb25cf (patch)
tree976e7b9a985f80e1d967e717028ace09f52048df
parenta58b17456a7fa4ff846c4883b96d6dee7e46a62f (diff)
downloadnode-new-0e392f3b68fecf8d45032a8f427e22f7f1cb25cf.tar.gz
net: do not set V4MAPPED on FreeBSD
V4MAPPED is not supported on recent FreeBSD versions, at least on 10.1. Thus, do not set this flag in net.connect on FreeBSD. Fixes #8540 and #9204. Reviewed-By: Colin Ihrig <cjihrig@gmail.com> PR-URL: https://github.com/joyent/node/pull/18204
-rw-r--r--doc/api/dns.markdown5
-rw-r--r--lib/net.js14
2 files changed, 15 insertions, 4 deletions
diff --git a/doc/api/dns.markdown b/doc/api/dns.markdown
index 9a8550aaf0..fe42c0f68a 100644
--- a/doc/api/dns.markdown
+++ b/doc/api/dns.markdown
@@ -259,8 +259,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 70baab3bd3..e6e48f4d9f 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -917,8 +917,18 @@ Socket.prototype.connect = function(options, cb) {
throw new RangeError('port should be >= 0 and < 65536: ' +
options.port);
- 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
+ // and
+ // https://svnweb.freebsd.org/base/head/lib/libc/net/getaddrinfo.c?r1=172052&r2=175955
+ // 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);