diff options
author | XadillaX <admin@xcoder.in> | 2017-05-21 18:02:33 +0800 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-06-09 19:09:28 +0200 |
commit | 27de36926bc8c4c6937a371257039cf17f16fb0e (patch) | |
tree | 05cbd8a80c9b531292e485903b2dda354704fdf6 /doc/api/dns.md | |
parent | c4a61b3ee55988b59888e96fae63dba60662bb98 (diff) | |
download | android-node-v8-27de36926bc8c4c6937a371257039cf17f16fb0e.tar.gz android-node-v8-27de36926bc8c4c6937a371257039cf17f16fb0e.tar.bz2 android-node-v8-27de36926bc8c4c6937a371257039cf17f16fb0e.zip |
dns: add resolveAny support
`dns.resolveAny` and `dns.resolve` with `"ANY"` has the similar behavior
like `$ dig <domain> any` and returns an array with several types of
records.
`dns.resolveAny` parses the result packet by several rules in turn.
Supported types:
* A
* AAAA
* CNAME
* MX
* NAPTR
* NS
* PTR
* SOA
* SRV
* TXT
Fixes: https://github.com/nodejs/node/issues/2848
PR-URL: https://github.com/nodejs/node/pull/13137
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Diffstat (limited to 'doc/api/dns.md')
-rw-r--r-- | doc/api/dns.md | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/doc/api/dns.md b/doc/api/dns.md index 42d93a14e7..94e64864b6 100644 --- a/doc/api/dns.md +++ b/doc/api/dns.md @@ -197,6 +197,7 @@ records. The type and structure of individual results varies based on `rrtype`: | `'SOA'` | start of authority records | {Object} | [`dns.resolveSoa()`][] | | `'SRV'` | service records | {Object} | [`dns.resolveSrv()`][] | | `'TXT'` | text records | {string} | [`dns.resolveTxt()`][] | +| `'ANY'` | any records | {Object} | [`dns.resolveAny()`][] | On error, `err` is an [`Error`][] object, where `err.code` is one of the [DNS error codes](#dns_error_codes). @@ -417,6 +418,51 @@ is a two-dimensional array of the text records available for `hostname` (e.g., one record. Depending on the use case, these could be either joined together or treated separately. +## dns.resolveAny(hostname, callback) + +- `hostname` {string} +- `callback` {Function} + - `err` {Error} + - `ret` {Object[][]} + +Uses the DNS protocol to resolve all records (also known as `ANY` or `*` query). +The `ret` argument passed to the `callback` function will be an array containing +various types of records. Each object has a property `type` that indicates the +type of the current record. And depending on the `type`, additional properties +will be present on the object: + +| Type | Properties | +|------|------------| +| `"A"` | `address` / `ttl` | +| `"AAAA"` | `address` / `ttl` | +| `"CNAME"` | `value` | +| `"MX"` | Refer to [`dns.resolveMx()`][] | +| `"NAPTR"` | Refer to [`dns.resolveNaptr()`][] | +| `"NS"` | `value` | +| `"PTR"` | `value` | +| `"SOA"` | Refer to [`dns.resolveSoa()`][] | +| `"SRV"` | Refer to [`dns.resolveSrv()`][] | +| `"TXT"` | This type of record contains an array property called `entries` which refers to [`dns.resolveTxt()`][], eg. `{ entries: ['...'], type: 'TXT' }` | + +Here is a example of the `ret` object passed to the callback: + +<!-- eslint-disable --> +```js +[ { type: 'A', address: '127.0.0.1', ttl: 299 }, + { type: 'CNAME', value: 'example.com' }, + { type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 }, + { type: 'NS', value: 'ns1.example.com', type: 'NS' }, + { type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] }, + { type: 'SOA', + nsname: 'ns1.example.com', + hostmaster: 'admin.example.com', + serial: 156696742, + refresh: 900, + retry: 900, + expire: 1800, + minttl: 60 } ] +``` + ## dns.reverse(ip, callback) <!-- YAML added: v0.1.16 @@ -531,6 +577,7 @@ uses. For instance, _they do not use the configuration from `/etc/hosts`_. [`dns.resolveSoa()`]: #dns_dns_resolvesoa_hostname_callback [`dns.resolveSrv()`]: #dns_dns_resolvesrv_hostname_callback [`dns.resolveTxt()`]: #dns_dns_resolvetxt_hostname_callback +[`dns.resolveAny()`]: #dns_dns_resolveany_hostname_callback [DNS error codes]: #dns_error_codes [Implementation considerations section]: #dns_implementation_considerations [supported `getaddrinfo` flags]: #dns_supported_getaddrinfo_flags |