From ce833215b19c8afed3ccbd8351850f9821adf1b9 Mon Sep 17 00:00:00 2001 From: Julien Gilli Date: Mon, 2 Mar 2015 15:50:25 -0800 Subject: [PATCH] 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. --- lib/net.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/net.js b/lib/net.js index 70baab3bd378..e6e48f4d9fd8 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);