Browse Source

doc: argument types for dns methods

Refs: https://github.com/nodejs/node/issues/9399
PR-URL: https://github.com/nodejs/node/pull/11764
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
v6
Amelia Clarke 8 years ago
committed by James M Snell
parent
commit
1faf136bfd
  1. 139
      doc/api/dns.md

139
doc/api/dns.md

@ -70,33 +70,25 @@ changes:
pr-url: https://github.com/nodejs/node/pull/744 pr-url: https://github.com/nodejs/node/pull/744
description: The `all` option is supported now. description: The `all` option is supported now.
--> -->
- `hostname` {string}
- `options` {integer | Object}
- `family` {integer} The record family. Must be `4` or `6`. IPv4
and IPv6 addresses are both returned by default.
- `hints` {number} One or more [supported `getaddrinfo` flags][]. Multiple
flags may be passed by bitwise `OR`ing their values.
- `all` {boolean} When `true`, the callback returns all resolved addresses in
an array. Otherwise, returns a single address. Defaults to `false`.
- `callback` {Function}
- `err` {Error}
- `address` {string} A string representation of an IPv4 or IPv6 address.
- `family` {integer} `4` or `6`, denoting the family of `address`.
Resolves a hostname (e.g. `'nodejs.org'`) into the first found A (IPv4) or Resolves a hostname (e.g. `'nodejs.org'`) into the first found A (IPv4) or
AAAA (IPv6) record. `options` can be an object or integer. If `options` is AAAA (IPv6) record. All `option` properties are optional. If `options` is an
not provided, then IPv4 and IPv6 addresses are both valid. If `options` is integer, then it must be `4` or `6` – if `options` is not provided, then IPv4
an integer, then it must be `4` or `6`. and IPv6 addresses are both returned if found.
Alternatively, `options` can be an object containing these properties: With the `all` option set to `true`, the arguments for `callback` change to
* `family` {number} - The record family. If present, must be the integer
`4` or `6`. If not provided, both IP v4 and v6 addresses are accepted.
* `hints`: {number} - If present, it should be one or more of the supported
`getaddrinfo` flags. If `hints` is not provided, then no flags are passed to
`getaddrinfo`. Multiple flags can be passed through `hints` by bitwise
`OR`ing their values.
See [supported `getaddrinfo` flags][] for more information on supported
flags.
* `all`: {boolean} - When `true`, the callback returns all resolved addresses
in an array, otherwise returns a single address. Defaults to `false`.
All properties are optional.
The `callback` function has arguments `(err, address, family)`. `address` is a
string representation of an IPv4 or IPv6 address. `family` is either the
integer `4` or `6` and denotes the family of `address` (not necessarily the
value initially passed to `lookup`).
With the `all` option set to `true`, the arguments change to
`(err, addresses)`, with `addresses` being an array of objects with the `(err, addresses)`, with `addresses` being an array of objects with the
properties `address` and `family`. properties `address` and `family`.
@ -147,6 +139,12 @@ on some operating systems (e.g FreeBSD 10.1).
<!-- YAML <!-- YAML
added: v0.11.14 added: v0.11.14
--> -->
- `address` {string}
- `port` {number}
- `callback` {Function}
- `err` {Error}
- `hostname` {string} e.g. `example.com`
- `service` {string} e.g. `http`
Resolves the given `address` and `port` into a hostname and service using Resolves the given `address` and `port` into a hostname and service using
the operating system's underlying `getnameinfo` implementation. the operating system's underlying `getnameinfo` implementation.
@ -155,10 +153,7 @@ If `address` is not a valid IP address, a `TypeError` will be thrown.
The `port` will be coerced to a number. If it is not a legal port, a `TypeError` The `port` will be coerced to a number. If it is not a legal port, a `TypeError`
will be thrown. will be thrown.
The callback has arguments `(err, hostname, service)`. The `hostname` and On an error, `err` is an [`Error`][] object, where `err.code` is the error code.
`service` arguments are strings (e.g. `'localhost'` and `'http'` respectively).
On error, `err` is an [`Error`][] object, where `err.code` is the error code.
```js ```js
const dns = require('dns'); const dns = require('dns');
@ -172,6 +167,11 @@ dns.lookupService('127.0.0.1', 22, (err, hostname, service) => {
<!-- YAML <!-- YAML
added: v0.1.27 added: v0.1.27
--> -->
- `hostname` {string}
- `rrtype` {string}
- `callback` {Function}
- `err` {Error}
- `addresses` {string[] | Object[] | string[][] | Object}
Uses the DNS protocol to resolve a hostname (e.g. `'nodejs.org'`) into an Uses the DNS protocol to resolve a hostname (e.g. `'nodejs.org'`) into an
array of the record types specified by `rrtype`. array of the record types specified by `rrtype`.
@ -208,18 +208,21 @@ changes:
description: This method now supports passing `options`, description: This method now supports passing `options`,
specifically `options.ttl`. specifically `options.ttl`.
--> -->
- `hostname` {string} Hostname to resolve.
- `options` {Object}
- `ttl` {boolean} Retrieve the Time-To-Live value (TTL) of each record.
When `true`, the callback receives an array of
`{ address: '1.2.3.4', ttl: 60 }` objects rather than an array of strings,
with the TTL expressed in seconds.
- `callback` {Function}
- `err` {Error}
- `addresses` {string[] | Object[]}
Uses the DNS protocol to resolve a IPv4 addresses (`A` records) for the Uses the DNS protocol to resolve a IPv4 addresses (`A` records) for the
`hostname`. The `addresses` argument passed to the `callback` function `hostname`. The `addresses` argument passed to the `callback` function
will contain an array of IPv4 addresses (e.g. will contain 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']`).
* `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[, options], callback) ## dns.resolve6(hostname[, options], callback)
<!-- YAML <!-- YAML
@ -230,22 +233,29 @@ changes:
description: This method now supports passing `options`, description: This method now supports passing `options`,
specifically `options.ttl`. specifically `options.ttl`.
--> -->
- `hostname` {string} Hostname to resolve.
- `options` {Object}
- `ttl` {boolean} Retrieve the Time-To-Live value (TTL) of each record.
When `true`, the callback receives an array of
`{ address: '0:1:2:3:4:5:6:7', ttl: 60 }` objects rather than an array of
strings, with the TTL expressed in seconds.
- `callback` {Function}
- `err` {Error}
- `addresses` {string[] | Object[]}
Uses the DNS protocol to resolve a IPv6 addresses (`AAAA` records) for the Uses the DNS protocol to resolve a IPv6 addresses (`AAAA` records) for the
`hostname`. The `addresses` argument passed to the `callback` function `hostname`. The `addresses` argument passed to the `callback` function
will contain an array of IPv6 addresses. 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) ## dns.resolveCname(hostname, callback)
<!-- YAML <!-- YAML
added: v0.3.2 added: v0.3.2
--> -->
- `hostname` {string}
- `callback` {Function}
- `err` {Error}
- `addresses` {string[]}
Uses the DNS protocol to resolve `CNAME` records for the `hostname`. The Uses the DNS protocol to resolve `CNAME` records for the `hostname`. The
`addresses` argument passed to the `callback` function `addresses` argument passed to the `callback` function
@ -256,6 +266,10 @@ will contain an array of canonical name records available for the `hostname`
<!-- YAML <!-- YAML
added: v0.1.27 added: v0.1.27
--> -->
- `hostname` {string}
- `callback` {Function}
- `err` {Error}
- `addresses` {Object[]}
Uses the DNS protocol to resolve mail exchange records (`MX` records) for the Uses the DNS protocol to resolve mail exchange records (`MX` records) for the
`hostname`. The `addresses` argument passed to the `callback` function will `hostname`. The `addresses` argument passed to the `callback` function will
@ -266,11 +280,14 @@ property (e.g. `[{priority: 10, exchange: 'mx.example.com'}, ...]`).
<!-- YAML <!-- YAML
added: v0.9.12 added: v0.9.12
--> -->
- `hostname` {string}
- `callback` {Function}
- `err` {Error}
- `addresses` {Object[]}
Uses the DNS protocol to resolve regular expression based records (`NAPTR` Uses the DNS protocol to resolve regular expression based records (`NAPTR`
records) for the `hostname`. The `callback` function has arguments records) for the `hostname`. The `addresses` argument passed to the `callback`
`(err, addresses)`. The `addresses` argument passed to the `callback` function function will contain an array of objects with the following properties:
will contain an array of objects with the following properties:
* `flags` * `flags`
* `service` * `service`
@ -296,16 +313,24 @@ For example:
<!-- YAML <!-- YAML
added: v0.1.90 added: v0.1.90
--> -->
- `hostname` {string}
- `callback` {Function}
- `err` {Error}
- `addresses` {string[]}
Uses the DNS protocol to resolve name server records (`NS` records) for the Uses the DNS protocol to resolve name server records (`NS` records) for the
`hostname`. The `addresses` argument passed to the `callback` function will `hostname`. The `addresses` argument passed to the `callback` function will
contain an array of name server records available for `hostname` contain an array of name server records available for `hostname`
(e.g. `['ns1.example.com', 'ns2.example.com']`). (e.g. `['ns1.example.com', 'ns2.example.com']`).
## dns.resolvePtr(hostname, callback) ## dns.resolvePtr(hostname)
<!-- YAML <!-- YAML
added: v6.0.0 added: v6.0.0
--> -->
- `hostname` {string}
- `callback` {Function}
- `err` {Error}
- `addresses` {string[]}
Uses the DNS protocol to resolve pointer records (`PTR` records) for the Uses the DNS protocol to resolve pointer records (`PTR` records) for the
`hostname`. The `addresses` argument passed to the `callback` function will `hostname`. The `addresses` argument passed to the `callback` function will
@ -315,9 +340,13 @@ be an array of strings containing the reply records.
<!-- YAML <!-- YAML
added: v0.11.10 added: v0.11.10
--> -->
- `hostname` {string}
- `callback` {Function}
- `err` {Error}
- `address` {Object}
Uses the DNS protocol to resolve a start of authority record (`SOA` record) for Uses the DNS protocol to resolve a start of authority record (`SOA` record) for
the `hostname`. The `addresses` argument passed to the `callback` function will the `hostname`. The `address` argument passed to the `callback` function will
be an object with the following properties: be an object with the following properties:
* `nsname` * `nsname`
@ -344,6 +373,10 @@ be an object with the following properties:
<!-- YAML <!-- YAML
added: v0.1.27 added: v0.1.27
--> -->
- `hostname` {string}
- `callback` {Function}
- `err` {Error}
- `addresses` {Object[]}
Uses the DNS protocol to resolve service records (`SRV` records) for the Uses the DNS protocol to resolve service records (`SRV` records) for the
`hostname`. The `addresses` argument passed to the `callback` function will `hostname`. The `addresses` argument passed to the `callback` function will
@ -367,6 +400,10 @@ be an array of objects with the following properties:
<!-- YAML <!-- YAML
added: v0.1.27 added: v0.1.27
--> -->
- `hostname` {string}
- `callback` {Function}
- `err` {Error}
- `addresses` {string[][]}
Uses the DNS protocol to resolve text queries (`TXT` records) for the Uses the DNS protocol to resolve text queries (`TXT` records) for the
`hostname`. The `addresses` argument passed to the `callback` function is `hostname`. The `addresses` argument passed to the `callback` function is
@ -379,13 +416,14 @@ treated separately.
<!-- YAML <!-- YAML
added: v0.1.16 added: v0.1.16
--> -->
- `ip` {string}
- `callback` {Function}
- `err` {Error}
- `hostnames` {string[]}
Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an
array of hostnames. array of hostnames.
The `callback` function has arguments `(err, hostnames)`, where `hostnames`
is an array of resolved hostnames for the given `ip`.
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 [DNS error codes][]. one of the [DNS error codes][].
@ -393,11 +431,12 @@ one of the [DNS error codes][].
<!-- YAML <!-- YAML
added: v0.11.3 added: v0.11.3
--> -->
- `servers` {string[]}
Sets the IP addresses of the servers to be used when resolving. The `servers` Sets the IP addresses of the servers to be used when resolving. The `servers`
argument is an array of IPv4 or IPv6 addresses. argument is an array of IPv4 or IPv6 addresses.
If a port specified on the address it will be removed. If a port is specified on the address, it will be removed.
An error will be thrown if an invalid address is provided. An error will be thrown if an invalid address is provided.

Loading…
Cancel
Save