Skip to content

Commit e14317a

Browse files
murgatroid99addaleax
authored andcommitted
dns: add dns.ALL hints flag constant
PR-URL: #32183 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent b494053 commit e14317a

File tree

7 files changed

+35
-10
lines changed

7 files changed

+35
-10
lines changed

doc/api/dns.md

+2
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ configured. Loopback addresses are not considered.
210210
* `dns.V4MAPPED`: If the IPv6 family was specified, but no IPv6 addresses were
211211
found, then return IPv4 mapped IPv6 addresses. It is not supported
212212
on some operating systems (e.g FreeBSD 10.1).
213+
* `dns.ALL`: If `dns.V4MAPPED` is specified, return resolved IPv6 addresses as
214+
well as IPv4 mapped IPv6 addresses.
213215

214216
## `dns.lookupService(address, port, callback)`
215217
<!-- YAML

lib/dns.js

+1
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

+3-5
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

+3
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

+21-4
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

+1-1
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

+4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ const hints = 512;
1515

1616
assert.notStrictEqual(hints, dns.ADDRCONFIG);
1717
assert.notStrictEqual(hints, dns.V4MAPPED);
18+
assert.notStrictEqual(hints, dns.ALL);
1819
assert.notStrictEqual(hints, dns.ADDRCONFIG | dns.V4MAPPED);
20+
assert.notStrictEqual(hints, dns.ADDRCONFIG | dns.ALL);
21+
assert.notStrictEqual(hints, dns.V4MAPPED | dns.ALL);
22+
assert.notStrictEqual(hints, dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL);
1923

2024
tls.connect({
2125
lookup: common.mustCall((host, options) => {

0 commit comments

Comments
 (0)