| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1bd7936 commit 0a3e5cc
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -200,7 +200,7 @@ will contain an array of IPv4 addresses (e.g. | |||
| 200 | 200 | rather than an array of strings. The TTL is expressed in seconds. | |
| 201 | 201 | * `callback` {Function} An `(err, result)` callback function. | |
| 202 | 202 | ||
| 203 | - ## dns.resolve6(hostname, callback) | ||
| 203 | + ## dns.resolve6(hostname[, options], callback) | ||
| 204 | 204 | <!-- YAML | |
| 205 | 205 | added: v0.1.16 | |
| 206 | 206 | --> | |
@@ -209,6 +209,13 @@ Uses the DNS protocol to resolve a IPv6 addresses (`AAAA` records) for the | |||
| 209 | 209 | `hostname`. The `addresses` argument passed to the `callback` function | |
| 210 | 210 | will contain an array of IPv6 addresses. | |
| 211 | 211 | ||
| 212 | + * `hostname` {String} Hostname to resolve. | ||
| 213 | + * `options` {Object} | ||
| 214 | + * `ttl` {Boolean} Retrieve the Time-To-Live value (TTL) of each record. | ||
| 215 | + The callback receives an array of `{ address: '0:1:2:3:4:5:6:7', ttl: 60 }` | ||
| 216 | + objects rather than an array of strings. The TTL is expressed in seconds. | ||
| 217 | + * `callback` {Function} An `(err, result)` callback function. | ||
| 218 | + | ||
| 212 | 219 | ## dns.resolveCname(hostname, callback) | |
| 213 | 220 | <!-- YAML | |
| 214 | 221 | added: v0.3.2 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -440,18 +440,27 @@ class QueryAaaaWrap: public QueryWrap { | |||
| 440 | 440 | HandleScope handle_scope(env()->isolate()); | |
| 441 | 441 | Context::Scope context_scope(env()->context()); | |
| 442 | 442 | ||
| 443 | - struct hostent* host; | ||
| 443 | + hostent* host; | ||
| 444 | + ares_addr6ttl addrttls[256]; | ||
| 445 | + int naddrttls = arraysize(addrttls); | ||
| 444 | 446 | ||
| 445 | - int status = ares_parse_aaaa_reply(buf, len, &host, nullptr, nullptr); | ||
| 447 | + int status = ares_parse_aaaa_reply(buf, len, &host, addrttls, &naddrttls); | ||
| 446 | 448 | if (status != ARES_SUCCESS) { | |
| 447 | 449 | ParseError(status); | |
| 448 | 450 | return; | |
| 449 | 451 | } | |
| 450 | 452 | ||
| 451 | 453 | Local<Array> addresses = HostentToAddresses(env(), host); | |
| 454 | + Local<Array> ttls = Array::New(env()->isolate(), naddrttls); | ||
| 455 | + | ||
| 456 | + auto context = env()->context(); | ||
| 457 | + for (int i = 0; i < naddrttls; i += 1) { | ||
| 458 | + auto value = Integer::New(env()->isolate(), addrttls[i].ttl); | ||
| 459 | + ttls->Set(context, i, value).FromJust(); | ||
| 460 | + } | ||
| 452 | 461 | ares_free_hostent(host); | |
| 453 | 462 | ||
| 454 | - this->CallOnComplete(addresses); | ||
| 463 | + CallOnComplete(addresses, ttls); | ||
| 455 | 464 | } | |
| 456 | 465 | }; | |
| 457 | 466 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,6 +81,27 @@ TEST(function test_resolve4_ttl(done) { | |||
| 81 | 81 | checkWrap(req); | |
| 82 | 82 | }); | |
| 83 | 83 | ||
| 84 | + TEST(function test_resolve6_ttl(done) { | ||
| 85 | + var req = dns.resolve6('google.com', { ttl: true }, function(err, result) { | ||
| 86 | + assert.ifError(err); | ||
| 87 | + assert.ok(result.length > 0); | ||
| 88 | + | ||
| 89 | + for (var i = 0; i < result.length; i++) { | ||
| 90 | + var item = result[i]; | ||
| 91 | + assert.ok(item); | ||
| 92 | + assert.strictEqual(typeof item, 'object'); | ||
| 93 | + assert.strictEqual(typeof item.ttl, 'number'); | ||
| 94 | + assert.strictEqual(typeof item.address, 'string'); | ||
| 95 | + assert.ok(item.ttl > 0); | ||
| 96 | + assert.ok(isIPv6(item.address)); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + done(); | ||
| 100 | + }); | ||
| 101 | + | ||
| 102 | + checkWrap(req); | ||
| 103 | + }); | ||
| 104 | + | ||
| 84 | 105 | TEST(function test_resolveMx(done) { | |
| 85 | 106 | var req = dns.resolveMx('gmail.com', function(err, result) { | |
| 86 | 107 | if (err) throw err; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments