Browse Source

De-indent dns.lookup

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
5e11b8a937
  1. 18
      lib/dns.js

18
lib/dns.js

@ -108,6 +108,7 @@ exports.getHostByAddr = function (address, family/*=4*/, callback) {
// Easy DNS A/AAAA look up // Easy DNS A/AAAA look up
// lookup(domain, [family,] callback) // lookup(domain, [family,] callback)
exports.lookup = function (domain, family, callback) { exports.lookup = function (domain, family, callback) {
// parse arguments
if (arguments.length === 2) { if (arguments.length === 2) {
callback = family; callback = family;
family = undefined; family = undefined;
@ -121,21 +122,27 @@ exports.lookup = function (domain, family, callback) {
throw new Error('invalid argument: "family" must be 4 or 6'); throw new Error('invalid argument: "family" must be 4 or 6');
} }
} }
if (!domain) { if (!domain) {
callback(null, null, family === 6 ? 6 : 4); callback(null, null, family === 6 ? 6 : 4);
return; return;
} }
var matchedFamily = net.isIP(domain); var matchedFamily = net.isIP(domain);
if (matchedFamily) { if (matchedFamily) {
callback(null, domain, matchedFamily); callback(null, domain, matchedFamily);
} else { return;
}
if (/\w\.local\.?$/.test(domain)) { if (/\w\.local\.?$/.test(domain)) {
// ANNOYING: In the case of mDNS domains use NSS in the thread pool. // ANNOYING: In the case of mDNS domains use NSS in the thread pool.
// I wish c-ares had better support. // I wish c-ares had better support.
process.binding('net').getaddrinfo(domain, 4, function (err, domains4) { process.binding('net').getaddrinfo(domain, 4, function (err, domains4) {
callback(err, domains4[0], 4); callback(err, domains4[0], 4);
}); });
} else { return;
}
if (family) { if (family) {
// resolve names for explicit address family // resolve names for explicit address family
var af = familyToSym(family); var af = familyToSym(family);
@ -150,7 +157,9 @@ exports.lookup = function (domain, family, callback) {
callback(err, []); callback(err, []);
} }
}); });
} else { return
}
// first resolve names for v4 and if that fails, try v6 // first resolve names for v4 and if that fails, try v6
channel.getHostByName(domain, dns.AF_INET, function (err, domains4) { channel.getHostByName(domain, dns.AF_INET, function (err, domains4) {
if (domains4 && domains4.length) { if (domains4 && domains4.length) {
@ -166,9 +175,6 @@ exports.lookup = function (domain, family, callback) {
}); });
} }
}); });
}
}
}
}; };

Loading…
Cancel
Save