11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst dnstools = require('../common/dns');
41cb0ef41Sopenharmony_ciconst { Resolver } = require('dns');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ciconst dgram = require('dgram');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst server = dgram.createSocket('udp4');
91cb0ef41Sopenharmony_ciconst resolver = new Resolver();
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciserver.bind(0, common.mustCall(() => {
121cb0ef41Sopenharmony_ci  resolver.setServers([`127.0.0.1:${server.address().port}`]);
131cb0ef41Sopenharmony_ci  resolver.reverse('123.45.67.89', common.mustCall((err, res) => {
141cb0ef41Sopenharmony_ci    assert.strictEqual(err.code, 'ECANCELLED');
151cb0ef41Sopenharmony_ci    assert.strictEqual(err.syscall, 'getHostByAddr');
161cb0ef41Sopenharmony_ci    assert.strictEqual(err.hostname, '123.45.67.89');
171cb0ef41Sopenharmony_ci    server.close();
181cb0ef41Sopenharmony_ci  }));
191cb0ef41Sopenharmony_ci}));
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciserver.on('message', common.mustCall((msg, { address, port }) => {
221cb0ef41Sopenharmony_ci  const parsed = dnstools.parseDNSPacket(msg);
231cb0ef41Sopenharmony_ci  const domain = parsed.questions[0].domain;
241cb0ef41Sopenharmony_ci  assert.strictEqual(domain, '89.67.45.123.in-addr.arpa');
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  // Do not send a reply.
271cb0ef41Sopenharmony_ci  resolver.cancel();
281cb0ef41Sopenharmony_ci}));
29