diff options
author | Rasmus Andersson <rasmus@notion.se> | 2010-08-12 18:51:23 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-08-12 16:25:45 -0700 |
commit | cf909e8725f12fa2f6356727cdae3110dd388c18 (patch) | |
tree | 3796b2173c55cf44b19dfb78ef7e6acd81ea6799 | |
parent | 758f12f34c23142d3fa63eb6d5d6d06b94885ccb (diff) | |
download | nodejs-cf909e8725f12fa2f6356727cdae3110dd388c18.tar.gz nodejs-cf909e8725f12fa2f6356727cdae3110dd388c18.tar.bz2 nodejs-cf909e8725f12fa2f6356727cdae3110dd388c18.zip |
added dns.getHostByAddr() -- resolve an external IP address to hostname(s)
-rw-r--r-- | lib/dns.js | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/dns.js b/lib/dns.js index 84d5d3b52..532f15abb 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -93,11 +93,25 @@ exports.resolve = function (domain, type_, callback_) { } -exports.getHostByName = function (domain, callback) { - channel.getHostByName(domain, dns.AF_INET, callback); +function familyToSym(family) { + 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 // lookup(domain, [family,] callback) @@ -132,7 +146,7 @@ exports.lookup = function (domain, family, callback) { } else { if (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) { if (!err && domains && domains.length) { if (family !== dns.isIP(domains[0])) { |