Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit 1d47b40

Browse files
author
Julien Gilli
committed
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.
1 parent f99eaef commit 1d47b40

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

doc/api/dns.markdown

+3-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,9 @@ The following flags can be passed as hints to `dns.lookup`.
259259
of addresses supported by the current system. For example, IPv4 addresses
260260
are only returned if the current system has at least one IPv4 address
261261
configured. Loopback addresses are not considered.
262-
- `dns.V4MAPPED`: If the IPv6 family was specified, but no IPv6 addresses
263-
were found, then return IPv4 mapped IPv6 addresses.
262+
- `dns.V4MAPPED`: If the IPv6 family was specified, but no IPv6 addresses were
263+
found, then return IPv4 mapped IPv6 addresses. Note that it is not supported
264+
on some operating systems (e.g FreeBSD 10.1).
264265

265266
## Implementation considerations
266267

lib/net.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,18 @@ Socket.prototype.connect = function(options, cb) {
917917
throw new RangeError('port should be >= 0 and < 65536: ' +
918918
options.port);
919919

920-
if (dnsopts.family !== 4 && dnsopts.family !== 6)
921-
dnsopts.hints = dns.ADDRCONFIG | dns.V4MAPPED;
920+
if (dnsopts.family !== 4 && dnsopts.family !== 6) {
921+
dnsopts.hints = dns.ADDRCONFIG;
922+
// The AI_V4MAPPED hint is not supported on FreeBSD, and getaddrinfo
923+
// returns EAI_BADFLAGS. However, it seems to be supported on most other
924+
// systems. See
925+
// http://lists.freebsd.org/pipermail/freebsd-bugs/2008-February/028260.html
926+
// and
927+
// https://svnweb.freebsd.org/base/head/lib/libc/net/getaddrinfo.c?r1=172052&r2=175955
928+
// for more information on the lack of support for FreeBSD.
929+
if (process.platform !== 'freebsd')
930+
dnsopts.hints |= dns.V4MAPPED;
931+
}
922932

923933
debug('connect: find host ' + host);
924934
debug('connect: dns options ' + dnsopts);

0 commit comments

Comments
 (0)