Skip to content

Commit b929988

Browse files
benjamingrjasnell
authored andcommitted
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: #5804 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent ccb7b45 commit b929988

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/dns.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const net = require('net');
43
const util = require('util');
54

65
const cares = process.binding('cares_wrap');
@@ -11,7 +10,7 @@ const GetAddrInfoReqWrap = cares.GetAddrInfoReqWrap;
1110
const GetNameInfoReqWrap = cares.GetNameInfoReqWrap;
1211
const QueryReqWrap = cares.QueryReqWrap;
1312

14-
const isIp = net.isIP;
13+
const isIP = cares.isIP;
1514
const isLegalPort = internalNet.isLegalPort;
1615

1716

@@ -148,7 +147,7 @@ exports.lookup = function lookup(hostname, options, callback) {
148147
return {};
149148
}
150149

151-
var matchedFamily = net.isIP(hostname);
150+
var matchedFamily = isIP(hostname);
152151
if (matchedFamily) {
153152
if (all) {
154153
callback(null, [{address: hostname, family: matchedFamily}]);
@@ -188,7 +187,7 @@ exports.lookupService = function(host, port, callback) {
188187
if (arguments.length !== 3)
189188
throw new Error('Invalid arguments');
190189

191-
if (cares.isIP(host) === 0)
190+
if (isIP(host) === 0)
192191
throw new TypeError('"host" argument needs to be a valid IP address');
193192

194193
if (port == null || !isLegalPort(port))
@@ -290,7 +289,7 @@ exports.setServers = function(servers) {
290289
var newSet = [];
291290

292291
servers.forEach(function(serv) {
293-
var ver = isIp(serv);
292+
var ver = isIP(serv);
294293

295294
if (ver)
296295
return newSet.push([ver, serv]);
@@ -299,13 +298,13 @@ exports.setServers = function(servers) {
299298

300299
// we have an IPv6 in brackets
301300
if (match) {
302-
ver = isIp(match[1]);
301+
ver = isIP(match[1]);
303302
if (ver)
304303
return newSet.push([ver, match[1]]);
305304
}
306305

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

310309
if (ver)
311310
return newSet.push([ver, s]);

0 commit comments

Comments
 (0)