Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: do not set V4MAPPED on FreeBSD #1555

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 0 additions & 5 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 12 additions & 2 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't make jslint complain about the long line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, surprisingly no. Want me to get rid of this?

$ make jslint
PYTHONPATH=tools/closure_linter/:tools/gflags/ /usr/bin/python tools/closure_linter/closure_linter/gjslint.py --unix_mode --strict --nojsdoc -r lib/ -r src/ --exclude_files lib/punycode.js
Skipping 1 file(s).
55 files checked, no errors found.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please.

// 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