mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
dns: add dns.ALL hints flag constant
PR-URL: https://github.com/nodejs/node/pull/32183 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
b494053745
commit
e14317a840
7 files changed
+35
-10
No files matched your search
@@ -210,6 +210,8 @@ 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. It is not supported
|
||||
on some operating systems (e.g FreeBSD 10.1).
|
||||
* `dns.ALL`: If `dns.V4MAPPED` is specified, return resolved IPv6 addresses as
|
||||
well as IPv4 mapped IPv6 addresses.
|
||||
|
||||
## `dns.lookupService(address, port, callback)`
|
||||
<!-- YAML
|
||||
|
||||
@@ -290,6 +290,7 @@ module.exports = {
|
||||
|
||||
// uv_getaddrinfo flags
|
||||
ADDRCONFIG: cares.AI_ADDRCONFIG,
|
||||
ALL: cares.AI_ALL,
|
||||
V4MAPPED: cares.AI_V4MAPPED,
|
||||
|
||||
// ERROR CODES
|
||||
|
||||
@@ -10,7 +10,8 @@ const {
|
||||
ChannelWrap,
|
||||
strerror,
|
||||
AI_ADDRCONFIG,
|
||||
AI_V4MAPPED
|
||||
AI_ALL,
|
||||
AI_V4MAPPED,
|
||||
} = internalBinding('cares_wrap');
|
||||
const IANA_DNS_PORT = 53;
|
||||
const IPv6RE = /^\[([^[\]]*)\]/;
|
||||
@@ -136,10 +137,7 @@ function bindDefaultResolver(target, source) {
|
||||
}
|
||||
|
||||
function validateHints(hints) {
|
||||
if (hints !== 0 &&
|
||||
hints !== AI_ADDRCONFIG &&
|
||||
hints !== AI_V4MAPPED &&
|
||||
hints !== (AI_ADDRCONFIG | AI_V4MAPPED)) {
|
||||
if ((hints & ~(AI_ADDRCONFIG | AI_ALL | AI_V4MAPPED)) !== 0) {
|
||||
throw new ERR_INVALID_OPT_VALUE('hints', hints);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2188,6 +2188,9 @@ void Initialize(Local<Object> target,
|
||||
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
|
||||
"AI_ADDRCONFIG"),
|
||||
Integer::New(env->isolate(), AI_ADDRCONFIG)).Check();
|
||||
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
|
||||
"AI_ALL"),
|
||||
Integer::New(env->isolate(), AI_ALL)).Check();
|
||||
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
|
||||
"AI_V4MAPPED"),
|
||||
Integer::New(env->isolate(), AI_V4MAPPED)).Check();
|
||||
|
||||
@@ -209,14 +209,14 @@ assert.deepStrictEqual(dns.getServers(), []);
|
||||
{
|
||||
/*
|
||||
* Make sure that dns.lookup throws if hints does not represent a valid flag.
|
||||
* (dns.V4MAPPED | dns.ADDRCONFIG) + 1 is invalid because:
|
||||
* - it's different from dns.V4MAPPED and dns.ADDRCONFIG.
|
||||
* - it's different from them bitwise ored.
|
||||
* (dns.V4MAPPED | dns.ADDRCONFIG | dns.ALL) + 1 is invalid because:
|
||||
* - it's different from dns.V4MAPPED and dns.ADDRCONFIG and dns.ALL.
|
||||
* - it's different from any subset of them bitwise ored.
|
||||
* - it's different from 0.
|
||||
* - it's an odd number different than 1, and thus is invalid, because
|
||||
* flags are either === 1 or even.
|
||||
*/
|
||||
const hints = (dns.V4MAPPED | dns.ADDRCONFIG) + 1;
|
||||
const hints = (dns.V4MAPPED | dns.ADDRCONFIG | dns.ALL) + 1;
|
||||
const err = {
|
||||
code: 'ERR_INVALID_OPT_VALUE',
|
||||
name: 'TypeError',
|
||||
@@ -254,11 +254,28 @@ dns.lookup('', {
|
||||
hints: dns.ADDRCONFIG | dns.V4MAPPED
|
||||
}, common.mustCall());
|
||||
|
||||
dns.lookup('', {
|
||||
hints: dns.ALL
|
||||
}, common.mustCall());
|
||||
|
||||
dns.lookup('', {
|
||||
hints: dns.V4MAPPED | dns.ALL
|
||||
}, common.mustCall());
|
||||
|
||||
dns.lookup('', {
|
||||
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL
|
||||
}, common.mustCall());
|
||||
|
||||
(async function() {
|
||||
await dnsPromises.lookup('', { family: 4, hints: 0 });
|
||||
await dnsPromises.lookup('', { family: 6, hints: dns.ADDRCONFIG });
|
||||
await dnsPromises.lookup('', { hints: dns.V4MAPPED });
|
||||
await dnsPromises.lookup('', { hints: dns.ADDRCONFIG | dns.V4MAPPED });
|
||||
await dnsPromises.lookup('', { hints: dns.ALL });
|
||||
await dnsPromises.lookup('', { hints: dns.V4MAPPED | dns.ALL });
|
||||
await dnsPromises.lookup('', {
|
||||
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL
|
||||
});
|
||||
})();
|
||||
|
||||
{
|
||||
|
||||
@@ -59,7 +59,7 @@ const net = require('net');
|
||||
// Test invalid hints
|
||||
{
|
||||
// connect({hint}, cb) and connect({hint})
|
||||
const hints = (dns.ADDRCONFIG | dns.V4MAPPED) + 42;
|
||||
const hints = (dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL) + 42;
|
||||
const hintOptBlocks = doConnect([{ hints }],
|
||||
() => common.mustNotCall());
|
||||
for (const fn of hintOptBlocks) {
|
||||
|
||||
@@ -15,7 +15,11 @@ const hints = 512;
|
||||
|
||||
assert.notStrictEqual(hints, dns.ADDRCONFIG);
|
||||
assert.notStrictEqual(hints, dns.V4MAPPED);
|
||||
assert.notStrictEqual(hints, dns.ALL);
|
||||
assert.notStrictEqual(hints, dns.ADDRCONFIG | dns.V4MAPPED);
|
||||
assert.notStrictEqual(hints, dns.ADDRCONFIG | dns.ALL);
|
||||
assert.notStrictEqual(hints, dns.V4MAPPED | dns.ALL);
|
||||
assert.notStrictEqual(hints, dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL);
|
||||
|
||||
tls.connect({
|
||||
lookup: common.mustCall((host, options) => {
|
||||
|
||||
Reference in new issue
Block a user