From b5432ae8191b5bb74895d64f8e315f8f8930b229 Mon Sep 17 00:00:00 2001 From: Julien Gilli Date: Mon, 2 Mar 2015 15:50:25 -0800 Subject: [PATCH 1/2] 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: https://github.com/joyent/node/issues/8540 Fixes: https://github.com/joyent/node/issues/9204 PR-URL: https://github.com/joyent/node/pull/18204 Reviewed-By: Colin Ihrig --- doc/api/dns.markdown | 5 +++-- lib/net.js | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) 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 867e1df7ccc252..97087a16709b8a 100644 --- a/lib/net.js +++ b/lib/net.js @@ -924,8 +924,18 @@ 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 + // 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); From ba187825a0a5aa81e9c379b292bf7bd8c2bad454 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 28 Apr 2015 20:49:15 -0400 Subject: [PATCH 2/2] Revert "dns: remove AI_V4MAPPED hint flag on FreeBSD" This reverts commit 04bea9f9c224d9f863f671a1ad52a3f392b292cb. --- lib/dns.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/dns.js b/lib/dns.js index 9334800e4da5c4..5668ecc05ef1ce 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -128,11 +128,6 @@ exports.lookup = function lookup(hostname, options, callback) { hints !== (exports.ADDRCONFIG | exports.V4MAPPED)) { throw new TypeError('invalid argument: hints must use valid flags'); } - - // FIXME(indutny): V4MAPPED on FreeBSD results in EAI_BADFLAGS, because - // the libc does not support it - if (process.platform === 'freebsd' && family !== 6) - hints &= ~exports.V4MAPPED; } else { family = options >>> 0; }