MCPcopy Index your code
hub / github.com/nodejs/node / createDnsServer

Function createDnsServer

test/parallel/test-http-autoselectfamily.js:33–58  ·  view source on GitHub ↗
(ipv6Addr, ipv4Addr, cb)

Source from the content-addressed store, hash-verified

31}
32
33function createDnsServer(ipv6Addr, ipv4Addr, cb) {
34 // Create a DNS server which replies with a AAAA and a A record for the same host
35 const socket = dgram.createSocket('udp4');
36
37 socket.on('message', common.mustCall((msg, { address, port }) => {
38 const parsed = parseDNSPacket(msg);
39 const domain = parsed.questions[0].domain;
40 assert.strictEqual(domain, 'example.org');
41
42 socket.send(writeDNSPacket({
43 id: parsed.id,
44 questions: parsed.questions,
45 answers: [
46 { type: 'AAAA', address: ipv6Addr, ttl: 123, domain: 'example.org' },
47 { type: 'A', address: ipv4Addr, ttl: 123, domain: 'example.org' },
48 ]
49 }), port, address);
50 }));
51
52 socket.bind(0, () => {
53 const resolver = new Resolver();
54 resolver.setServers([`127.0.0.1:${socket.address().port}`]);
55
56 cb({ dnsServer: socket, lookup: _lookup.bind(null, resolver) });
57 });
58}
59
60// Test that IPV4 is reached if IPV6 is not reachable
61{

Callers 1

Calls 9

parseDNSPacketFunction · 0.85
writeDNSPacketFunction · 0.85
createSocketMethod · 0.80
setServersMethod · 0.80
cbFunction · 0.70
sendMethod · 0.65
addressMethod · 0.65
onMethod · 0.45
bindMethod · 0.45

Tested by

no test coverage detected