Skip to content

Commit 3fef69b

Browse files
benjamingrFishrock123
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 <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
1 parent b352cc7 commit 3fef69b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/dns.js

Lines changed: 6 additions & 7 deletions
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');
@@ -10,7 +9,7 @@ const GetAddrInfoReqWrap = cares.GetAddrInfoReqWrap;
109
const GetNameInfoReqWrap = cares.GetNameInfoReqWrap;
1110
const QueryReqWrap = cares.QueryReqWrap;
1211

13-
const isIp = net.isIP;
12+
const isIP = cares.isIP;
1413

1514

1615
function errnoException(err, syscall, hostname) {
@@ -146,7 +145,7 @@ exports.lookup = function lookup(hostname, options, callback) {
146145
return {};
147146
}
148147

149-
var matchedFamily = net.isIP(hostname);
148+
var matchedFamily = isIP(hostname);
150149
if (matchedFamily) {
151150
if (all) {
152151
callback(null, [{address: hostname, family: matchedFamily}]);
@@ -186,7 +185,7 @@ exports.lookupService = function(host, port, callback) {
186185
if (arguments.length !== 3)
187186
throw new Error('invalid arguments');
188187

189-
if (cares.isIP(host) === 0)
188+
if (isIP(host) === 0)
190189
throw new TypeError('host needs to be a valid IP address');
191190

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

288287
servers.forEach(function(serv) {
289-
var ver = isIp(serv);
288+
var ver = isIP(serv);
290289

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

296295
// we have an IPv6 in brackets
297296
if (match) {
298-
ver = isIp(match[1]);
297+
ver = isIP(match[1]);
299298
if (ver)
300299
return newSet.push([ver, match[1]]);
301300
}
302301

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

306305
if (ver)
307306
return newSet.push([ver, s]);

0 commit comments

Comments
 (0)