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

dns: refactor internal/dns/promises.js #27081

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
4 changes: 3 additions & 1 deletion doc/api/dns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

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 {
Expand Down Expand Up @@ -60,7 +60,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]));
}
}

Expand All @@ -75,7 +75,7 @@ function onlookupall(err, addresses) {
const addr = addresses[i];
addresses[i] = {
address: addr,
family: family || (isIPv4(addr) ? 4 : 6)
family: family || isIP(addr)
};
}

Expand Down
6 changes: 3 additions & 3 deletions lib/internal/dns/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
} = require('internal/dns/utils');
const { codes, dnsException } = require('internal/errors');
const { toASCII } = require('internal/idna');
const { isIP, isIPv4, isLegalPort } = require('internal/net');
const { isIP, isLegalPort } = require('internal/net');
const {
getaddrinfo,
getnameinfo,
Expand All @@ -31,7 +31,7 @@ function onlookup(err, addresses) {
return;
}

const family = this.family ? this.family : isIPv4(addresses[0]) ? 4 : 6;
const family = this.family ? this.family : isIP(addresses[0]);
this.resolve({ address: addresses[0], family });
}

Expand All @@ -48,7 +48,7 @@ function onlookupall(err, addresses) {

addresses[i] = {
address,
family: family ? family : isIPv4(addresses[i]) ? 4 : 6
family: family ? family : isIP(addresses[i])
};
}

Expand Down