diff --git a/doc/api/dns.md b/doc/api/dns.md index d5af7aef8bfec7..22899e625c3f0b 100644 --- a/doc/api/dns.md +++ b/doc/api/dns.md @@ -154,7 +154,9 @@ changes: * `callback` {Function} - `err` {Error} - `address` {string} A string representation of an IPv4 or IPv6 address. - - `family` {integer} `4` or `6`, denoting the family of `address`. + - `family` {integer} `4` or `6`, denoting the family of `address`, or `0` if + the address is not an IPv4 or IPv6 address. `0` is a likely indicator of a + bug in the name resolution service used by the operating system. Resolves a hostname (e.g. `'nodejs.org'`) into the first found A (IPv4) or AAAA (IPv6) record. All `option` properties are optional. If `options` is an diff --git a/lib/dns.js b/lib/dns.js index b212983c4412f7..835eb91ee16b91 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -25,7 +25,7 @@ const { Object } = primordials; const cares = internalBinding('cares_wrap'); const { toASCII } = require('internal/idna'); -const { isIP, isIPv4, isLegalPort } = require('internal/net'); +const { isIP, isLegalPort } = require('internal/net'); const { customPromisifyArgs } = require('internal/util'); const errors = require('internal/errors'); const { @@ -62,7 +62,7 @@ function onlookup(err, addresses) { if (this.family) { this.callback(null, addresses[0], this.family); } else { - this.callback(null, addresses[0], isIPv4(addresses[0]) ? 4 : 6); + this.callback(null, addresses[0], isIP(addresses[0])); } } @@ -77,7 +77,7 @@ function onlookupall(err, addresses) { const addr = addresses[i]; addresses[i] = { address: addr, - family: family || (isIPv4(addr) ? 4 : 6) + family: family || isIP(addr) }; }