Skip to content

Commit

Permalink
net: do not set V4MAPPED on FreeBSD
Browse files Browse the repository at this point in the history
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: nodejs/node-v0.x-archive#8540
Fixes: nodejs/node-v0.x-archive#9204
PR-URL: nodejs/node-v0.x-archive#18204
PR-URL: #1555
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
Julien Gilli authored and rvagg committed Aug 4, 2015
1 parent df1994f commit 9bc2e26
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions doc/api/dns.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 10 additions & 2 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,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);
Expand Down

0 comments on commit 9bc2e26

Please sign in to comment.