Browse Source

dns: use isIp consistently

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: https://github.com/nodejs/node/pull/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>
process-exit-stdio-flushing
Benjamin Gruenbaum 9 years ago
committed by James M Snell
parent
commit
b9299884dc
  1. 13
      lib/dns.js

13
lib/dns.js

@ -1,6 +1,5 @@
'use strict'; 'use strict';
const net = require('net');
const util = require('util'); const util = require('util');
const cares = process.binding('cares_wrap'); const cares = process.binding('cares_wrap');
@ -11,7 +10,7 @@ const GetAddrInfoReqWrap = cares.GetAddrInfoReqWrap;
const GetNameInfoReqWrap = cares.GetNameInfoReqWrap; const GetNameInfoReqWrap = cares.GetNameInfoReqWrap;
const QueryReqWrap = cares.QueryReqWrap; const QueryReqWrap = cares.QueryReqWrap;
const isIp = net.isIP; const isIP = cares.isIP;
const isLegalPort = internalNet.isLegalPort; const isLegalPort = internalNet.isLegalPort;
@ -148,7 +147,7 @@ exports.lookup = function lookup(hostname, options, callback) {
return {}; return {};
} }
var matchedFamily = net.isIP(hostname); var matchedFamily = isIP(hostname);
if (matchedFamily) { if (matchedFamily) {
if (all) { if (all) {
callback(null, [{address: hostname, family: matchedFamily}]); callback(null, [{address: hostname, family: matchedFamily}]);
@ -188,7 +187,7 @@ exports.lookupService = function(host, port, callback) {
if (arguments.length !== 3) if (arguments.length !== 3)
throw new Error('Invalid arguments'); throw new Error('Invalid arguments');
if (cares.isIP(host) === 0) if (isIP(host) === 0)
throw new TypeError('"host" argument needs to be a valid IP address'); throw new TypeError('"host" argument needs to be a valid IP address');
if (port == null || !isLegalPort(port)) if (port == null || !isLegalPort(port))
@ -290,7 +289,7 @@ exports.setServers = function(servers) {
var newSet = []; var newSet = [];
servers.forEach(function(serv) { servers.forEach(function(serv) {
var ver = isIp(serv); var ver = isIP(serv);
if (ver) if (ver)
return newSet.push([ver, serv]); return newSet.push([ver, serv]);
@ -299,13 +298,13 @@ exports.setServers = function(servers) {
// we have an IPv6 in brackets // we have an IPv6 in brackets
if (match) { if (match) {
ver = isIp(match[1]); ver = isIP(match[1]);
if (ver) if (ver)
return newSet.push([ver, match[1]]); return newSet.push([ver, match[1]]);
} }
var s = serv.split(/:\d+$/)[0]; var s = serv.split(/:\d+$/)[0];
ver = isIp(s); ver = isIP(s);
if (ver) if (ver)
return newSet.push([ver, s]); return newSet.push([ver, s]);

Loading…
Cancel
Save