dns: Add dns.ALL hints flag constant by murgatroid99 · Pull Request #32183 · nodejs/node · GitHub
Skip to content
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
2 changes: 2 additions & 0 deletions doc/api/dns.md
1 change: 1 addition & 0 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ module.exports = {

// uv_getaddrinfo flags
ADDRCONFIG: cares.AI_ADDRCONFIG,
ALL: cares.AI_ALL,
V4MAPPED: cares.AI_V4MAPPED,

// ERROR CODES
Expand Down
8 changes: 3 additions & 5 deletions lib/internal/dns/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /^\[([^[\]]*)\]/;
Expand Down Expand Up @@ -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);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,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();
Expand Down
25 changes: 21 additions & 4 deletions test/parallel/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
});
})();

{
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-net-connect-options-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-tls-connect-hints-option.js