ShadowNode

Use Node.js in your end devices(QQ: 796448809)

View the Project on GitHub yodaos-project/ShadowNode

Platform Support

The following shows dns module APIs available for each platform.

  Linux
(Ubuntu)
Raspbian
(Raspberry Pi)
NuttX
(STM32F4-Discovery)
TizenRT
(Artik053)
dns.lookup O O X O

※ dns.lookup currently only returns IPv4 addresses. Support for IPv6 addresses are on the roadmap.

DNS

The dns module provides a method to perform host name resolution. The functionality is implemented on top of the underlying operation system facilities. Please see Implementation considerations section.

The following properties are flags which can be passed as hints for the dns.lookup() method.

dns.ADDRCONFIG

Returned address types are determined by the types of addresses supported by the current system.

dns.V4MAPPED

If the IPv6 family was specified, but no IPv6 addresses were found, then return IPv4 mapped IPv6 addresses.

dns.lookup(hostname[, options], callback)

Resolves a hostname (e.g. iotjs.net) into the first found A (IPv4) or AAAA (IPv6) record. All option properties are option. If option is a number, then it must be 4. If options is not provided, then IPv4 addresses are returned if found.

On error, err is an Error object where err.code is the error code returned by the underlying system call.

The dns.lookup() does not necessarily do DNS requests to resolve a hostname. The implementation uses an operating system facility to associate names with addresses. Please read the Implementation considerations section for more system dependent information.

Example

var dns = require('dns');
dns.lookup ('localhost', 4, function(err, ip, family) {
  console.log('ip: ' + ip + ' family: ' + family);
});
// ip: 127.0.0.1 family: 4

var options = {
  family: 4,
  hints: dns.ADDRCONFIG,
};

dns.lookup ('iotjs.net', options, function(err, ip, family) {
  console.log('ip: ' + ip + ' family: ' + family);
});
// ip: 192.30.252.154 family: 4

Implementation considerations

The current implementation only supports host name resolution to IPv4 addresses.

On NuttX currently only valid IPv4 addresses are allowed for the dns.lookup() method.