Skip to content

Commit

Permalink
dns: use isIp consistently
Browse files Browse the repository at this point in the history
Currently the DNS module imports isIP from both cares and `net` and
uses both of them both throughout the code base. This PR removes the
direct dependency `dns` has on `net` and uses `isIp` from c-ares all
the time. Note that both functions do the same thing.

PR-URL: #5804
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>

Conflicts:
	lib/dns.js
  • Loading branch information
benjamingr authored and Fishrock123 committed Mar 22, 2016
1 parent b352cc7 commit 3fef69b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/dns.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const net = require('net');
const util = require('util');

const cares = process.binding('cares_wrap');
Expand All @@ -10,7 +9,7 @@ const GetAddrInfoReqWrap = cares.GetAddrInfoReqWrap;
const GetNameInfoReqWrap = cares.GetNameInfoReqWrap;
const QueryReqWrap = cares.QueryReqWrap;

const isIp = net.isIP;
const isIP = cares.isIP;


function errnoException(err, syscall, hostname) {
Expand Down Expand Up @@ -146,7 +145,7 @@ exports.lookup = function lookup(hostname, options, callback) {
return {};
}

var matchedFamily = net.isIP(hostname);
var matchedFamily = isIP(hostname);
if (matchedFamily) {
if (all) {
callback(null, [{address: hostname, family: matchedFamily}]);
Expand Down Expand Up @@ -186,7 +185,7 @@ exports.lookupService = function(host, port, callback) {
if (arguments.length !== 3)
throw new Error('invalid arguments');

if (cares.isIP(host) === 0)
if (isIP(host) === 0)
throw new TypeError('host needs to be a valid IP address');

if (typeof port !== 'number')
Expand Down Expand Up @@ -286,7 +285,7 @@ exports.setServers = function(servers) {
var newSet = [];

servers.forEach(function(serv) {
var ver = isIp(serv);
var ver = isIP(serv);

if (ver)
return newSet.push([ver, serv]);
Expand All @@ -295,13 +294,13 @@ exports.setServers = function(servers) {

// we have an IPv6 in brackets
if (match) {
ver = isIp(match[1]);
ver = isIP(match[1]);
if (ver)
return newSet.push([ver, match[1]]);
}

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

if (ver)
return newSet.push([ver, s]);
Expand Down

0 comments on commit 3fef69b

Please sign in to comment.