dns: rename domain to hostname
A follow-up commit will save the domain name on the request object but we can't call that property 'domain' because that gets intercepted by src/node.cc and lib/domain.js to implement the node.js feature of the same name. To avoid confusion, rename all variables called 'domain' to 'hostname'.
This commit is contained in:
parent
4234bcce48
commit
ceb8740a63
@ -21,19 +21,19 @@ resolves the IP addresses which are returned.
|
|||||||
console.log('addresses: ' + JSON.stringify(addresses));
|
console.log('addresses: ' + JSON.stringify(addresses));
|
||||||
|
|
||||||
addresses.forEach(function (a) {
|
addresses.forEach(function (a) {
|
||||||
dns.reverse(a, function (err, domains) {
|
dns.reverse(a, function (err, hostnames) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('reverse for ' + a + ': ' + JSON.stringify(domains));
|
console.log('reverse for ' + a + ': ' + JSON.stringify(hostnames));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
## dns.lookup(domain, [family], callback)
|
## dns.lookup(hostname, [family], callback)
|
||||||
|
|
||||||
Resolves a domain (e.g. `'google.com'`) into the first found A (IPv4) or
|
Resolves a hostname (e.g. `'google.com'`) into the first found A (IPv4) or
|
||||||
AAAA (IPv6) record.
|
AAAA (IPv6) record.
|
||||||
The `family` can be the integer `4` or `6`. Defaults to `null` that indicates
|
The `family` can be the integer `4` or `6`. Defaults to `null` that indicates
|
||||||
both Ip v4 and v6 address family.
|
both Ip v4 and v6 address family.
|
||||||
@ -45,13 +45,13 @@ necessarily the value initially passed to `lookup`).
|
|||||||
|
|
||||||
On error, `err` is an `Error` object, where `err.code` is the error code.
|
On error, `err` is an `Error` object, where `err.code` is the error code.
|
||||||
Keep in mind that `err.code` will be set to `'ENOENT'` not only when
|
Keep in mind that `err.code` will be set to `'ENOENT'` not only when
|
||||||
the domain does not exist but also when the lookup fails in other ways
|
the hostname does not exist but also when the lookup fails in other ways
|
||||||
such as no available file descriptors.
|
such as no available file descriptors.
|
||||||
|
|
||||||
|
|
||||||
## dns.resolve(domain, [rrtype], callback)
|
## dns.resolve(hostname, [rrtype], callback)
|
||||||
|
|
||||||
Resolves a domain (e.g. `'google.com'`) into an array of the record types
|
Resolves a hostname (e.g. `'google.com'`) into an array of the record types
|
||||||
specified by rrtype. Valid rrtypes are `'A'` (IPV4 addresses, default),
|
specified by rrtype. Valid rrtypes are `'A'` (IPV4 addresses, default),
|
||||||
`'AAAA'` (IPV6 addresses), `'MX'` (mail exchange records), `'TXT'` (text
|
`'AAAA'` (IPV6 addresses), `'MX'` (mail exchange records), `'TXT'` (text
|
||||||
records), `'SRV'` (SRV records), `'PTR'` (used for reverse IP lookups),
|
records), `'SRV'` (SRV records), `'PTR'` (used for reverse IP lookups),
|
||||||
@ -65,54 +65,54 @@ On error, `err` is an `Error` object, where `err.code` is
|
|||||||
one of the error codes listed below.
|
one of the error codes listed below.
|
||||||
|
|
||||||
|
|
||||||
## dns.resolve4(domain, callback)
|
## dns.resolve4(hostname, callback)
|
||||||
|
|
||||||
The same as `dns.resolve()`, but only for IPv4 queries (`A` records).
|
The same as `dns.resolve()`, but only for IPv4 queries (`A` records).
|
||||||
`addresses` is an array of IPv4 addresses (e.g.
|
`addresses` is an array of IPv4 addresses (e.g.
|
||||||
`['74.125.79.104', '74.125.79.105', '74.125.79.106']`).
|
`['74.125.79.104', '74.125.79.105', '74.125.79.106']`).
|
||||||
|
|
||||||
## dns.resolve6(domain, callback)
|
## dns.resolve6(hostname, callback)
|
||||||
|
|
||||||
The same as `dns.resolve4()` except for IPv6 queries (an `AAAA` query).
|
The same as `dns.resolve4()` except for IPv6 queries (an `AAAA` query).
|
||||||
|
|
||||||
|
|
||||||
## dns.resolveMx(domain, callback)
|
## dns.resolveMx(hostname, callback)
|
||||||
|
|
||||||
The same as `dns.resolve()`, but only for mail exchange queries (`MX` records).
|
The same as `dns.resolve()`, but only for mail exchange queries (`MX` records).
|
||||||
|
|
||||||
`addresses` is an array of MX records, each with a priority and an exchange
|
`addresses` is an array of MX records, each with a priority and an exchange
|
||||||
attribute (e.g. `[{'priority': 10, 'exchange': 'mx.example.com'},...]`).
|
attribute (e.g. `[{'priority': 10, 'exchange': 'mx.example.com'},...]`).
|
||||||
|
|
||||||
## dns.resolveTxt(domain, callback)
|
## dns.resolveTxt(hostname, callback)
|
||||||
|
|
||||||
The same as `dns.resolve()`, but only for text queries (`TXT` records).
|
The same as `dns.resolve()`, but only for text queries (`TXT` records).
|
||||||
`addresses` is an array of the text records available for `domain` (e.g.,
|
`addresses` is an array of the text records available for `hostname` (e.g.,
|
||||||
`['v=spf1 ip4:0.0.0.0 ~all']`).
|
`['v=spf1 ip4:0.0.0.0 ~all']`).
|
||||||
|
|
||||||
## dns.resolveSrv(domain, callback)
|
## dns.resolveSrv(hostname, callback)
|
||||||
|
|
||||||
The same as `dns.resolve()`, but only for service records (`SRV` records).
|
The same as `dns.resolve()`, but only for service records (`SRV` records).
|
||||||
`addresses` is an array of the SRV records available for `domain`. Properties
|
`addresses` is an array of the SRV records available for `hostname`. Properties
|
||||||
of SRV records are priority, weight, port, and name (e.g.,
|
of SRV records are priority, weight, port, and name (e.g.,
|
||||||
`[{'priority': 10, {'weight': 5, 'port': 21223, 'name': 'service.example.com'}, ...]`).
|
`[{'priority': 10, {'weight': 5, 'port': 21223, 'name': 'service.example.com'}, ...]`).
|
||||||
|
|
||||||
## dns.resolveNs(domain, callback)
|
## dns.resolveNs(hostname, callback)
|
||||||
|
|
||||||
The same as `dns.resolve()`, but only for name server records (`NS` records).
|
The same as `dns.resolve()`, but only for name server records (`NS` records).
|
||||||
`addresses` is an array of the name server records available for `domain`
|
`addresses` is an array of the name server records available for `hostname`
|
||||||
(e.g., `['ns1.example.com', 'ns2.example.com']`).
|
(e.g., `['ns1.example.com', 'ns2.example.com']`).
|
||||||
|
|
||||||
## dns.resolveCname(domain, callback)
|
## dns.resolveCname(hostname, callback)
|
||||||
|
|
||||||
The same as `dns.resolve()`, but only for canonical name records (`CNAME`
|
The same as `dns.resolve()`, but only for canonical name records (`CNAME`
|
||||||
records). `addresses` is an array of the canonical name records available for
|
records). `addresses` is an array of the canonical name records available for
|
||||||
`domain` (e.g., `['bar.example.com']`).
|
`hostname` (e.g., `['bar.example.com']`).
|
||||||
|
|
||||||
## dns.reverse(ip, callback)
|
## dns.reverse(ip, callback)
|
||||||
|
|
||||||
Reverse resolves an ip address to an array of domain names.
|
Reverse resolves an ip address to an array of hostnames.
|
||||||
|
|
||||||
The callback has arguments `(err, domains)`.
|
The callback has arguments `(err, hostnames)`.
|
||||||
|
|
||||||
On error, `err` is an `Error` object, where `err.code` is
|
On error, `err` is an `Error` object, where `err.code` is
|
||||||
one of the error codes listed below.
|
one of the error codes listed below.
|
||||||
@ -143,7 +143,7 @@ Each DNS query can return one of the following error codes:
|
|||||||
- `dns.NOTIMP`: DNS server does not implement requested operation.
|
- `dns.NOTIMP`: DNS server does not implement requested operation.
|
||||||
- `dns.REFUSED`: DNS server refused query.
|
- `dns.REFUSED`: DNS server refused query.
|
||||||
- `dns.BADQUERY`: Misformatted DNS query.
|
- `dns.BADQUERY`: Misformatted DNS query.
|
||||||
- `dns.BADNAME`: Misformatted domain name.
|
- `dns.BADNAME`: Misformatted hostname.
|
||||||
- `dns.BADFAMILY`: Unsupported address family.
|
- `dns.BADFAMILY`: Unsupported address family.
|
||||||
- `dns.BADRESP`: Misformatted DNS reply.
|
- `dns.BADRESP`: Misformatted DNS reply.
|
||||||
- `dns.CONNREFUSED`: Could not contact DNS servers.
|
- `dns.CONNREFUSED`: Could not contact DNS servers.
|
||||||
@ -160,4 +160,3 @@ Each DNS query can return one of the following error codes:
|
|||||||
- `dns.LOADIPHLPAPI`: Error loading iphlpapi.dll.
|
- `dns.LOADIPHLPAPI`: Error loading iphlpapi.dll.
|
||||||
- `dns.ADDRGETNETWORKPARAMS`: Could not find GetNetworkParams function.
|
- `dns.ADDRGETNETWORKPARAMS`: Could not find GetNetworkParams function.
|
||||||
- `dns.CANCELLED`: DNS query cancelled.
|
- `dns.CANCELLED`: DNS query cancelled.
|
||||||
|
|
||||||
|
18
lib/dns.js
18
lib/dns.js
@ -94,8 +94,8 @@ function onlookup(err, addresses) {
|
|||||||
|
|
||||||
|
|
||||||
// Easy DNS A/AAAA look up
|
// Easy DNS A/AAAA look up
|
||||||
// lookup(domain, [family,] callback)
|
// lookup(hostname, [family,] callback)
|
||||||
exports.lookup = function(domain, family, callback) {
|
exports.lookup = function(hostname, family, callback) {
|
||||||
// parse arguments
|
// parse arguments
|
||||||
if (arguments.length === 2) {
|
if (arguments.length === 2) {
|
||||||
callback = family;
|
callback = family;
|
||||||
@ -110,7 +110,7 @@ exports.lookup = function(domain, family, callback) {
|
|||||||
}
|
}
|
||||||
callback = makeAsync(callback);
|
callback = makeAsync(callback);
|
||||||
|
|
||||||
if (!domain) {
|
if (!hostname) {
|
||||||
callback(null, null, family === 6 ? 6 : 4);
|
callback(null, null, family === 6 ? 6 : 4);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -119,14 +119,14 @@ exports.lookup = function(domain, family, callback) {
|
|||||||
// localhost entry from c:\WINDOWS\system32\drivers\etc\hosts
|
// localhost entry from c:\WINDOWS\system32\drivers\etc\hosts
|
||||||
// See http://daniel.haxx.se/blog/2011/02/21/localhost-hack-on-windows/
|
// See http://daniel.haxx.se/blog/2011/02/21/localhost-hack-on-windows/
|
||||||
// TODO Remove this once c-ares handles this problem.
|
// TODO Remove this once c-ares handles this problem.
|
||||||
if (process.platform == 'win32' && domain == 'localhost') {
|
if (process.platform == 'win32' && hostname == 'localhost') {
|
||||||
callback(null, '127.0.0.1', 4);
|
callback(null, '127.0.0.1', 4);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
var matchedFamily = net.isIP(domain);
|
var matchedFamily = net.isIP(hostname);
|
||||||
if (matchedFamily) {
|
if (matchedFamily) {
|
||||||
callback(null, domain, matchedFamily);
|
callback(null, hostname, matchedFamily);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ exports.lookup = function(domain, family, callback) {
|
|||||||
family: family,
|
family: family,
|
||||||
oncomplete: onlookup
|
oncomplete: onlookup
|
||||||
};
|
};
|
||||||
var err = cares.getaddrinfo(req, domain, family);
|
var err = cares.getaddrinfo(req, hostname, family);
|
||||||
if (err) throw errnoException(err, 'getaddrinfo');
|
if (err) throw errnoException(err, 'getaddrinfo');
|
||||||
|
|
||||||
callback.immediately = true;
|
callback.immediately = true;
|
||||||
@ -181,7 +181,7 @@ exports.resolveNaptr = resolveMap.NAPTR = resolver('queryNaptr');
|
|||||||
exports.reverse = resolveMap.PTR = resolver('getHostByAddr');
|
exports.reverse = resolveMap.PTR = resolver('getHostByAddr');
|
||||||
|
|
||||||
|
|
||||||
exports.resolve = function(domain, type_, callback_) {
|
exports.resolve = function(hostname, type_, callback_) {
|
||||||
var resolver, callback;
|
var resolver, callback;
|
||||||
if (util.isString(type_)) {
|
if (util.isString(type_)) {
|
||||||
resolver = resolveMap[type_];
|
resolver = resolveMap[type_];
|
||||||
@ -192,7 +192,7 @@ exports.resolve = function(domain, type_, callback_) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (util.isFunction(resolver)) {
|
if (util.isFunction(resolver)) {
|
||||||
return resolver(domain, callback);
|
return resolver(hostname, callback);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Unknown type "' + type_ + '"');
|
throw new Error('Unknown type "' + type_ + '"');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user