added dns.getHostByAddr() -- resolve an external IP address to hostname(s)

This commit is contained in:
Rasmus Andersson 2010-08-12 18:51:23 +02:00 коммит произвёл Ryan Dahl
Родитель 758f12f34c
Коммит cf909e8725
1 изменённых файлов: 18 добавлений и 4 удалений

Просмотреть файл

@ -93,11 +93,25 @@ exports.resolve = function (domain, type_, callback_) {
} }
exports.getHostByName = function (domain, callback) { function familyToSym(family) {
channel.getHostByName(domain, dns.AF_INET, callback); if (family !== dns.AF_INET && family !== dns.AF_INET6) {
family = (family === 6) ? dns.AF_INET6 : dns.AF_INET;
}
return family;
}
exports.getHostByName = function (domain, family/*=4*/, callback) {
if (typeof family === 'function') { callback = family; family = null; }
channel.getHostByName(domain, familyToSym(family), callback);
};
exports.getHostByAddr = function (address, family/*=4*/, callback) {
if (typeof family === 'function') { callback = family; family = null; }
channel.getHostByAddr(address, familyToSym(family), callback);
}; };
var net;
// Easy DNS A/AAAA look up // Easy DNS A/AAAA look up
// lookup(domain, [family,] callback) // lookup(domain, [family,] callback)
@ -132,7 +146,7 @@ exports.lookup = function (domain, family, callback) {
} else { } else {
if (family) { if (family) {
// resolve names for explicit address family // resolve names for explicit address family
var af = (family === 4) ? dns.AF_INET : dns.AF_INET6; var af = familyToSym(family);
channel.getHostByName(domain, af, function (err, domains) { channel.getHostByName(domain, af, function (err, domains) {
if (!err && domains && domains.length) { if (!err && domains && domains.length) {
if (family !== dns.isIP(domains[0])) { if (family !== dns.isIP(domains[0])) {