dns: add order option and support ipv6first

PR-URL: https://github.com/nodejs/node/pull/52492
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
This commit is contained in:
Paolo Insogna
2024-04-17 17:24:28 +02:00
committed by GitHub
parent b41347e496
commit 7e89369166
21 changed files with 400 additions and 90 deletions

View File

@@ -8,6 +8,9 @@ const dns = require('dns');
dns.setDefaultResultOrder('ipv4first');
let dnsOrder = dns.getDefaultResultOrder();
assert.ok(dnsOrder === 'ipv4first');
dns.setDefaultResultOrder('ipv6first');
dnsOrder = dns.getDefaultResultOrder();
assert.ok(dnsOrder === 'ipv6first');
dns.setDefaultResultOrder('verbatim');
dnsOrder = dns.getDefaultResultOrder();
assert.ok(dnsOrder === 'verbatim');
@@ -15,10 +18,26 @@ assert.ok(dnsOrder === 'verbatim');
{
(async function() {
const result = await dns.promises.lookup('localhost');
const result1 = await dns.promises.lookup('localhost', { verbatim: true });
const result1 = await dns.promises.lookup('localhost', { order: 'verbatim' });
assert.ok(result !== undefined);
assert.ok(result1 !== undefined);
assert.ok(result.address === result1.address);
assert.ok(result.family === result1.family);
})().then(common.mustCall());
}
{
(async function() {
const result = await dns.promises.lookup('localhost', { order: 'ipv4first' });
assert.ok(result !== undefined);
assert.ok(result.family === 4);
})().then(common.mustCall());
}
if (common.hasIPv6) {
(async function() {
const result = await dns.promises.lookup('localhost', { order: 'ipv6first' });
assert.ok(result !== undefined);
assert.ok(result.family === 6);
})().then(common.mustCall());
}

View File

@@ -722,7 +722,7 @@ console.log(`looking up ${addresses.INET4_HOST}..`);
const cares = internalBinding('cares_wrap');
const req = new cares.GetAddrInfoReqWrap();
cares.getaddrinfo(req, addresses.INET4_HOST, 4,
/* hints */ 0, /* verbatim */ true);
/* hints */ 0, /* order */ cares.DNS_ORDER_VERBATIM);
req.oncomplete = function(err, domains) {
assert.strictEqual(err, 0);