dns: add dns.ALL hints flag constant · nodejs/node@e14317a · GitHub
Skip to content

Commit e14317a

Browse files
murgatroid99addaleax
authored andcommitted
dns: add dns.ALL hints flag constant
PR-URL: #32183 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent b494053 commit e14317a

7 files changed

Lines changed: 35 additions & 10 deletions

File tree

doc/api/dns.md

Lines changed: 2 additions & 0 deletions

lib/dns.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ module.exports = {
290290

291291
// uv_getaddrinfo flags
292292
ADDRCONFIG: cares.AI_ADDRCONFIG,
293+
ALL: cares.AI_ALL,
293294
V4MAPPED: cares.AI_V4MAPPED,
294295

295296
// ERROR CODES

lib/internal/dns/utils.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const {
1010
ChannelWrap,
1111
strerror,
1212
AI_ADDRCONFIG,
13-
AI_V4MAPPED
13+
AI_ALL,
14+
AI_V4MAPPED,
1415
} = internalBinding('cares_wrap');
1516
const IANA_DNS_PORT = 53;
1617
const IPv6RE = /^\[([^[\]]*)\]/;
@@ -136,10 +137,7 @@ function bindDefaultResolver(target, source) {
136137
}
137138

138139
function validateHints(hints) {
139-
if (hints !== 0 &&
140-
hints !== AI_ADDRCONFIG &&
141-
hints !== AI_V4MAPPED &&
142-
hints !== (AI_ADDRCONFIG | AI_V4MAPPED)) {
140+
if ((hints & ~(AI_ADDRCONFIG | AI_ALL | AI_V4MAPPED)) !== 0) {
143141
throw new ERR_INVALID_OPT_VALUE('hints', hints);
144142
}
145143
}

src/cares_wrap.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,9 @@ void Initialize(Local<Object> target,
21882188
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
21892189
"AI_ADDRCONFIG"),
21902190
Integer::New(env->isolate(), AI_ADDRCONFIG)).Check();
2191+
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
2192+
"AI_ALL"),
2193+
Integer::New(env->isolate(), AI_ALL)).Check();
21912194
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
21922195
"AI_V4MAPPED"),
21932196
Integer::New(env->isolate(), AI_V4MAPPED)).Check();

test/parallel/test-dns.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,14 @@ assert.deepStrictEqual(dns.getServers(), []);
209209
{
210210
/*
211211
* Make sure that dns.lookup throws if hints does not represent a valid flag.
212-
* (dns.V4MAPPED | dns.ADDRCONFIG) + 1 is invalid because:
213-
* - it's different from dns.V4MAPPED and dns.ADDRCONFIG.
214-
* - it's different from them bitwise ored.
212+
* (dns.V4MAPPED | dns.ADDRCONFIG | dns.ALL) + 1 is invalid because:
213+
* - it's different from dns.V4MAPPED and dns.ADDRCONFIG and dns.ALL.
214+
* - it's different from any subset of them bitwise ored.
215215
* - it's different from 0.
216216
* - it's an odd number different than 1, and thus is invalid, because
217217
* flags are either === 1 or even.
218218
*/
219-
const hints = (dns.V4MAPPED | dns.ADDRCONFIG) + 1;
219+
const hints = (dns.V4MAPPED | dns.ADDRCONFIG | dns.ALL) + 1;
220220
const err = {
221221
code: 'ERR_INVALID_OPT_VALUE',
222222
name: 'TypeError',
@@ -254,11 +254,28 @@ dns.lookup('', {
254254
hints: dns.ADDRCONFIG | dns.V4MAPPED
255255
}, common.mustCall());
256256

257+
dns.lookup('', {
258+
hints: dns.ALL
259+
}, common.mustCall());
260+
261+
dns.lookup('', {
262+
hints: dns.V4MAPPED | dns.ALL
263+
}, common.mustCall());
264+
265+
dns.lookup('', {
266+
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL
267+
}, common.mustCall());
268+
257269
(async function() {
258270
await dnsPromises.lookup('', { family: 4, hints: 0 });
259271
await dnsPromises.lookup('', { family: 6, hints: dns.ADDRCONFIG });
260272
await dnsPromises.lookup('', { hints: dns.V4MAPPED });
261273
await dnsPromises.lookup('', { hints: dns.ADDRCONFIG | dns.V4MAPPED });
274+
await dnsPromises.lookup('', { hints: dns.ALL });
275+
await dnsPromises.lookup('', { hints: dns.V4MAPPED | dns.ALL });
276+
await dnsPromises.lookup('', {
277+
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL
278+
});
262279
})();
263280

264281
{

test/parallel/test-net-connect-options-port.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const net = require('net');
5959
// Test invalid hints
6060
{
6161
// connect({hint}, cb) and connect({hint})
62-
const hints = (dns.ADDRCONFIG | dns.V4MAPPED) + 42;
62+
const hints = (dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL) + 42;
6363
const hintOptBlocks = doConnect([{ hints }],
6464
() => common.mustNotCall());
6565
for (const fn of hintOptBlocks) {

test/parallel/test-tls-connect-hints-option.js

Lines changed: 4 additions & 0 deletions

0 commit comments

Comments
 (0)