dns: do not indicate invalid IPs are IPv6 · nodejs/node@09cdc37 (original) (raw)

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -154,7 +154,9 @@ changes:
154 154 * `callback` {Function}
155 155 - `err` {Error}
156 156 - `address` {string} A string representation of an IPv4 or IPv6 address.
157 -- `family` {integer} `4` or `6`, denoting the family of `address`.
157 +- `family` {integer} `4` or `6`, denoting the family of `address`, or `0` if
158 + the address is not an IPv4 or IPv6 address. `0` is a likely indicator of a
159 + bug in the name resolution service used by the operating system.
158 160
159 161 Resolves a hostname (e.g. `'nodejs.org'`) into the first found A (IPv4) or
160 162 AAAA (IPv6) record. All `option` properties are optional. If `options` is an
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ const { Object } = primordials;
25 25
26 26 const cares = internalBinding('cares_wrap');
27 27 const { toASCII } = require('internal/idna');
28 -const { isIP, isIPv4, isLegalPort } = require('internal/net');
28 +const { isIP, isLegalPort } = require('internal/net');
29 29 const { customPromisifyArgs } = require('internal/util');
30 30 const errors = require('internal/errors');
31 31 const {
@@ -62,7 +62,7 @@ function onlookup(err, addresses) {
62 62 if (this.family) {
63 63 this.callback(null, addresses[0], this.family);
64 64 } else {
65 -this.callback(null, addresses[0], isIPv4(addresses[0]) ? 4 : 6);
65 +this.callback(null, addresses[0], isIP(addresses[0]));
66 66 }
67 67 }
68 68
@@ -77,7 +77,7 @@ function onlookupall(err, addresses) {
77 77 const addr = addresses[i];
78 78 addresses[i] = {
79 79 address: addr,
80 -family: family |
80 +family: family |
81 81 };
82 82 }
83 83