Fixes issue with ::1 port 5300 requests

Now the address is wrapped in `[]` in order to prevent ::1 port 5300
being interpreted as ::1:5300. Wrapping the IPv4 address in `[]` does
seem to have any effect on correct domain name resolution. In order to
prevent issues if a user inputs an address with brackets, they are
removed from the string if present before being re-added when it is
passed to `setServers`. I have also removed the JSDoc comment as this
will be added in a seperate PR

Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com>
This commit is contained in:
Matthew Nickson 2022-04-15 19:59:32 +01:00
parent 8c8eeaf627
commit a680331dd7
No known key found for this signature in database
GPG key ID: BF229DCFD4748E05

View file

@ -88,17 +88,12 @@ exports.pingAsync = function (hostname, ipv6 = false) {
});
};
/**
* Resolves a given record using the specified DNS server
* @param {string} hostname The hostname of the record to lookup
* @param {string} resolver_server The DNS server to use
* @param {string} resolver_port The port the DNS server is listening on
* @param {string} rrtype The type of record to request
* @returns {Promise} Promise object represents DNS lookup result
*/
exports.dnsResolve = function (hostname, resolver_server, resolver_port, rrtype) {
const resolver = new Resolver();
resolver.setServers([`${resolver_server}:${resolver_port}`]);
// Remove brackets from IPv6 addresses so we can re-add them to
// prevent issues with ::1:5300 (::1 port 5300)
resolver_server = resolver_server.replace("[", "").replace("]", "");
resolver.setServers([`[${resolver_server}]:${resolver_port}`]);
return new Promise((resolve, reject) => {
if (rrtype == "PTR") {
resolver.reverse(hostname, (err, records) => {