From c31b507b947d5b4803dd96a7c9a09fd2112085ab Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 26 Oct 2016 07:51:34 +0200 Subject: [PATCH 1/2] dns: implement {ttl: true} for dns.resolve4() Add an option to retrieve the Time-To-Live of the A record. PR-URL: https://github.com/nodejs/node/pull/9296 Refs: https://github.com/nodejs/node/issues/5893 Reviewed-By: James M Snell Reviewed-By: Roman Reiss --- doc/api/dns.md | 9 ++++++++- lib/dns.js | 14 ++++++++++++-- src/cares_wrap.cc | 33 +++++++++++++++++---------------- test/internet/test-dns.js | 20 ++++++++++++++++++++ 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/doc/api/dns.md b/doc/api/dns.md index e930892cedc927..2dd6fa60bc0a2a 100644 --- a/doc/api/dns.md +++ b/doc/api/dns.md @@ -183,7 +183,7 @@ corresponding lookup methods. On error, `err` is an [`Error`][] object, where `err.code` is one of the error codes listed [here](#dns_error_codes). -## dns.resolve4(hostname, callback) +## dns.resolve4(hostname[, options], callback) @@ -193,6 +193,13 @@ Uses the DNS protocol to resolve a IPv4 addresses (`A` records) for the will contain an array of IPv4 addresses (e.g. `['74.125.79.104', '74.125.79.105', '74.125.79.106']`). +* `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: '1.2.3.4', ttl: 60 }` objects + rather than an array of strings. The TTL is expressed in seconds. +* `callback` {Function} An `(err, result)` callback function. + ## dns.resolve6(hostname, callback) @@ -209,6 +209,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)