Ben Noordhuis
8 years ago
committed by
Myles Borins
No known key found for this signature in database
GPG Key ID: 933B01F40B5CA946
3 changed files with
41 additions and
4 deletions
-
doc/api/dns.md
-
src/cares_wrap.cc
-
test/internet/test-dns.js
|
|
@ -212,7 +212,7 @@ will contain an array of IPv4 addresses (e.g. |
|
|
|
rather than an array of strings. The TTL is expressed in seconds. |
|
|
|
* `callback` {Function} An `(err, result)` callback function. |
|
|
|
|
|
|
|
## dns.resolve6(hostname, callback) |
|
|
|
## dns.resolve6(hostname[, options], callback) |
|
|
|
<!-- YAML |
|
|
|
added: v0.1.16 |
|
|
|
--> |
|
|
@ -221,6 +221,13 @@ Uses the DNS protocol to resolve a IPv6 addresses (`AAAA` records) for the |
|
|
|
`hostname`. The `addresses` argument passed to the `callback` function |
|
|
|
will contain an array of IPv6 addresses. |
|
|
|
|
|
|
|
* `hostname` {String} Hostname to resolve. |
|
|
|
* `options` {Object} |
|
|
|
* `ttl` {Boolean} Retrieve the Time-To-Live value (TTL) of each record. |
|
|
|
The callback receives an array of `{ address: '0:1:2:3:4:5:6:7', ttl: 60 }` |
|
|
|
objects rather than an array of strings. The TTL is expressed in seconds. |
|
|
|
* `callback` {Function} An `(err, result)` callback function. |
|
|
|
|
|
|
|
## dns.resolveCname(hostname, callback) |
|
|
|
<!-- YAML |
|
|
|
added: v0.3.2 |
|
|
|
|
|
@ -441,18 +441,27 @@ class QueryAaaaWrap: public QueryWrap { |
|
|
|
HandleScope handle_scope(env()->isolate()); |
|
|
|
Context::Scope context_scope(env()->context()); |
|
|
|
|
|
|
|
struct hostent* host; |
|
|
|
hostent* host; |
|
|
|
ares_addr6ttl addrttls[256]; |
|
|
|
int naddrttls = arraysize(addrttls); |
|
|
|
|
|
|
|
int status = ares_parse_aaaa_reply(buf, len, &host, nullptr, nullptr); |
|
|
|
int status = ares_parse_aaaa_reply(buf, len, &host, addrttls, &naddrttls); |
|
|
|
if (status != ARES_SUCCESS) { |
|
|
|
ParseError(status); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
Local<Array> addresses = HostentToAddresses(env(), host); |
|
|
|
Local<Array> ttls = Array::New(env()->isolate(), naddrttls); |
|
|
|
|
|
|
|
auto context = env()->context(); |
|
|
|
for (int i = 0; i < naddrttls; i += 1) { |
|
|
|
auto value = Integer::New(env()->isolate(), addrttls[i].ttl); |
|
|
|
ttls->Set(context, i, value).FromJust(); |
|
|
|
} |
|
|
|
ares_free_hostent(host); |
|
|
|
|
|
|
|
this->CallOnComplete(addresses); |
|
|
|
CallOnComplete(addresses, ttls); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
@ -81,6 +81,27 @@ TEST(function test_resolve4_ttl(done) { |
|
|
|
checkWrap(req); |
|
|
|
}); |
|
|
|
|
|
|
|
TEST(function test_resolve6_ttl(done) { |
|
|
|
const req = dns.resolve6('google.com', { ttl: true }, function(err, result) { |
|
|
|
assert.ifError(err); |
|
|
|
assert.ok(result.length > 0); |
|
|
|
|
|
|
|
for (let i = 0; i < result.length; i++) { |
|
|
|
const item = result[i]; |
|
|
|
assert.ok(item); |
|
|
|
assert.strictEqual(typeof item, 'object'); |
|
|
|
assert.strictEqual(typeof item.ttl, 'number'); |
|
|
|
assert.strictEqual(typeof item.address, 'string'); |
|
|
|
assert.ok(item.ttl > 0); |
|
|
|
assert.ok(isIPv6(item.address)); |
|
|
|
} |
|
|
|
|
|
|
|
done(); |
|
|
|
}); |
|
|
|
|
|
|
|
checkWrap(req); |
|
|
|
}); |
|
|
|
|
|
|
|
TEST(function test_resolveMx(done) { |
|
|
|
const req = dns.resolveMx('gmail.com', function(err, result) { |
|
|
|
if (err) throw err; |
|
|
|