Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,8 @@ void ChannelWrap::Setup() {
options.timeout = timeout_;
options.tries = tries_;
options.qcache_max_ttl = 0;
// Resolver APIs always perform DNS queries and must not consult hosts files.
options.lookups = const_cast<char*>("b");

int r;
if (!library_inited_) {
Expand All @@ -908,7 +910,7 @@ void ChannelWrap::Setup() {

/* We do the call to ares_init_option for caller. */
int optmask = ARES_OPT_FLAGS | ARES_OPT_TIMEOUTMS | ARES_OPT_SOCK_STATE_CB |
ARES_OPT_TRIES | ARES_OPT_QUERY_CACHE;
ARES_OPT_TRIES | ARES_OPT_QUERY_CACHE | ARES_OPT_LOOKUPS;

if (max_timeout_ > 0) {
options.maxtimeout = max_timeout_;
Expand Down
14 changes: 0 additions & 14 deletions test/parallel/test-c-ares.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,3 @@ dns.lookup('::1', common.mustSucceed((result, addressType) => {

assert.throws(() => dnsPromises.resolve('www.google.com', val), err);
});

// Windows doesn't usually have an entry for localhost 127.0.0.1 in
// C:\Windows\System32\drivers\etc\hosts
// so we disable this test on Windows.
// IBMi reports `ENOTFOUND` when get hostname by address 127.0.0.1
if (!common.isWindows && !common.isIBMi) {
dns.reverse('127.0.0.1', common.mustSucceed((domains) => {
assert.ok(Array.isArray(domains));
}));

(async function() {
assert.ok(Array.isArray(await dnsPromises.reverse('127.0.0.1')));
})().then(common.mustCall());
}
37 changes: 37 additions & 0 deletions test/parallel/test-dns-reverse-dns-only.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const dns = require('dns');
const dnstools = require('../common/dns');

const server = dgram.createSocket('udp4');
const resolver = new dns.Resolver();
const expectedHostname = 'reverse-dns-only.example';

server.on('message', common.mustCall((msg, { address, port }) => {
const parsed = dnstools.parseDNSPacket(msg);
const question = parsed.questions[0];

assert.strictEqual(question.domain, '1.0.0.127.in-addr.arpa');
assert.strictEqual(question.type, 'PTR');

server.send(dnstools.writeDNSPacket({
id: parsed.id,
questions: parsed.questions,
answers: [{
type: 'PTR',
domain: question.domain,
value: expectedHostname,
}],
}), port, address);
}));

server.bind(0, common.mustCall(() => {
resolver.setServers([`127.0.0.1:${server.address().port}`]);
resolver.reverse('127.0.0.1', common.mustSucceed((hostnames) => {
assert.deepStrictEqual(hostnames, [expectedHostname]);
server.close();
}));
}));
Loading