Skip to content

Commit

Permalink
Merge pull request #38 from McSneaky/main
Browse files Browse the repository at this point in the history
Fix passing DNS server IP to DNS lookup
  • Loading branch information
billywhizz committed Jun 30, 2024
2 parents 33b1d01 + 2664ee6 commit bff54be
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 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 {void}
*/
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

0 comments on commit bff54be

Please sign in to comment.