Skip to content
Prev Previous commit
Next Next commit
remove isValidIp and check for 0 instead
  • Loading branch information
benjamingr committed Mar 17, 2016
commit 6fe93ed8063458928d8851e60eaca9190eb35571
10 changes: 3 additions & 7 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ function errnoException(err, syscall, hostname) {
return ex;
}

function validIpVersion(isIpResult) {
return isIpResult !== 0;
}

// c-ares invokes a callback either synchronously or asynchronously,
// but the dns API should always invoke a callback asynchronously.
//
Expand Down Expand Up @@ -311,23 +307,23 @@ exports.setServers = function(servers) {
const newSet = servers.map((serv) => {
var ipVersion = isIp(serv);

if (validIpVersion(ipVersion)) {
if (ipVersion !== 0) {
return [ver, serv];
}
const match = serv.match(/\[(.*)\](:\d+)?/);

// we have an IPv6 in brackets
if (match) {
ipVersion = isIp(match[1]);
if (validIpVersion(ipVersion)) {
if (ipVersion !== 0) {
return [ver, match[1]];
}
}

var s = serv.split(/:\d+$/)[0];
ipVersion = isIp(s);

if (validIpVersion(ipVersion)) {
if (ipVersion !== 0) {
return [ver, s];
}

Expand Down