Skip to content

Commit

Permalink
Fix passing DNS server IP to DNS lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
McSneaky authored Jun 28, 2024
1 parent d649b17 commit 591e1a5
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions lib/dns/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ class Resolver {
})
}

/**
*
* @param {string} query Domain to query from DNS server
* @param {function(err, ip)} onRecord Callback function, error as first param, found IP as 2nd
* @param {string} address DNS server IP
* @param {number} port DNS server port
* @param {Uint8Array} buf Buffer for DNS response
* @returns
*/
lookup (query = 'localhost', onRecord = (err, ip) => {}, address = '127.0.0.1', port = 53, buf = new Uint8Array(65536)) {
if (this.cache.has(query)) {
console.log('dns from cache')
Expand All @@ -107,10 +116,15 @@ class Resolver {
onRecord(null, ip)
return
}
const ips = readResolv()
if (ips.length) {
address = ips[0]
// Default DNS server address is unchanged,
// try to read address from `/etc/resolv.conf`
if (address === '127.0.0.1') {
const ips = readResolv()
if (ips.length) {
address = ips[0]
}
}

let timer
const node = new Node(this.loop)
node.peer(address, port)
Expand Down Expand Up @@ -196,3 +210,6 @@ function lookup (hostname) {
}

export { Resolver, lookup }


let resolver = new Resolver()

0 comments on commit 591e1a5

Please sign in to comment.