Browse Source

De-indent dns.lookup

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

82
lib/dns.js

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

Loading…
Cancel
Save