镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

dns docs are missing that family = 0 for dns.lookup is allowed #28159

Description

@daprahamian
  • Node.js Version: 12.2
  • OS: macOs
  • Scope (install, code, runtime, meta, other?): runtime
  • Module (and version) (if relevant): dns, net, tls

Quick question: is dns.lookup(url, 0, callback) supported as part of Node's API? The documentation says Must be 4 or 6, and any positive integer other than 4 or 6 will return a TypeError [ERR_INVALID_OPT_VALUE]: The value "2" is invalid for option "family". But passing in 0 does not error. Is this expected? If so, is this something stable that developers can rely on?

// The following are all expected to work
dns.lookup('www.google.com', 4, err => {
  console.log(err); // null
});
dns.lookup('www.google.com', 6, err => {
  console.log(err); // null
});
dns.lookup('www.google.com', err => {
  console.log(err); // null
});

// The following should error
try {
  dns.lookup('www.google.com', 1, () => {});
} catch (e) {
  console.log(e); // TypeError [ERR_INVALID_OPT_VALUE]: The value "1" is invalid for option "family"
}
try {
  dns.lookup('www.google.com', 2, () => {});
} catch (e) {
  console.log(e); // TypeError [ERR_INVALID_OPT_VALUE]: The value "2" is invalid for option "family"
}
try {
  dns.lookup('www.google.com', 3, () => {});
} catch (e) {
  console.log(e); // TypeError [ERR_INVALID_OPT_VALUE]: The value "3" is invalid for option "family"
}
try {
  dns.lookup('www.google.com', 5, () => {});
} catch (e) {
  console.log(e); // TypeError [ERR_INVALID_OPT_VALUE]: The value "5" is invalid for option "family"
}

// Asking about this one:
dns.lookup('www.google.com', 0, err => {
  console.log(err); // null <-- is this correct?
});

Activity

  1. addaleax commented on Jun 10, 2019

    @addaleax
    Member

    0 stands for AF_UNSPEC, which, quoting the man page, means:

    The value AF_UNSPEC indicates that getaddrinfo() should return socket addresses for any address family (either IPv4 or IPv6, for example) that can be used with node and service.

    So, the Node.js documentation is clearly wrong, and omitting an important feature here (although it’s the default behaviour). I’m moving this over to the main repo as it’s a documentation bug.

  2. changed the title [-]is family = 0 for dns.lookup allowed?[/-] [+]dns docs are missing that family = 0 for dns.lookup is allowed[/+] on Jun 10, 2019
  3. transferred this issue fromnodejs/helpon Jun 10, 2019
  4. added
    dnsIssues and PRs related to the dns subsystem.
    docIssues and PRs related to Node.js documentation.
    on Jun 10, 2019
  5. ZYSzys commented on Jun 14, 2019

    @ZYSzys
    Member

    Fixed via #28163.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dnsIssues and PRs related to the dns subsystem.docIssues and PRs related to Node.js documentation.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions