GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add version of dns.lookup that returns all results · Issue #736 · nodejs/node

Add version of dns.lookup that returns all results #736

New issue
Copy link
New issue
Copy link
Closed
Closed
Add version of dns.lookup that returns all results#736
Copy link
Labels
dnsIssues and PRs related to the dns subsystem.

Description

@jsha
jsha
opened on Feb 6, 2015
Issue body actions

The dns module provides two sets of methods: the resolve family, which directly resolves using the DNS protocol, and the lookup function, which uses the system resolver (through getaddrinfo) and returns at most one address.

It's often preferable to use the system resolver, since it can use things like mDNS. However, using the dns.lookup API makes it impossible to receive multiple IP addresses in response to a DNS query (See #708 for motivating example).

Proposal: Add a new function dns.lookupAll that behaves like dns.lookup, but returns all addresses given by getaddrinfo.

Activity

  1. cjihrig commented on Feb 6, 2015

    @cjihrig
    cjihrig
    on Feb 6, 2015
    Contributor
    More actions

    This seems like a pretty simple addition. I'd be fine with working on it, if others find it useful. I think the window is currently open for a minor version bump too.

  2. brendanashworth
    added
    dnsIssues and PRs related to the dns subsystem.
    on Feb 6, 2015
  3. bnoordhuis commented on Feb 6, 2015

    @bnoordhuis
    bnoordhuis
    on Feb 6, 2015
    Member
    More actions

    This seems like a perfectly reasonable addition to me. It doesn't even need a new function; dns.lookup() already looks up all the addresses but it's intentionally crippled to only report the first one. We can simply extend it like this:

    dns.lookup('google.com', { all: true }, function(err, addrs) { /* ... */ });  // strawman

    The callback gets the address family as its third argument now. For the { all: true } case, we probably want to drop that and report the family in the addrs array. It's a list of strings now, that would have to change to a list of objects.

  4. silverwind commented on Feb 6, 2015

    @silverwind
    silverwind
    on Feb 6, 2015
    Contributor
    More actions

    I'll start working on this according to @bnoordhuis's proposal, if that's ok with you, @cjihrig.

  5. cjihrig commented on Feb 6, 2015

    @cjihrig
    cjihrig
    on Feb 6, 2015
    Contributor
    More actions

    @silverwind sure. I was thinking you might just want to change this line to point to another function. And the callback would change from function(err, address, family) to function(err, addresses), where each element in addresses would be something like {ip: '127.0.0.1', family: 4}.

  6. silverwind commented on Feb 6, 2015

    @silverwind
    silverwind
    on Feb 6, 2015
    Contributor
    More actions

    My first approach would've been to modify onlookup with additional logic and add a req.all property. You think that a second function would be cleaner?

  7. cjihrig commented on Feb 6, 2015

    @cjihrig
    cjihrig
    on Feb 6, 2015
    Contributor
    More actions

    I figured it would be simpler, with less chance of breaking existing code, to just point to a new function. The two functions will have very little overlap except checking for an error.

  8. silverwind commented on Feb 6, 2015

    @silverwind
    silverwind
    on Feb 6, 2015
    Contributor
    More actions

    True, I'll add an second function then, definitely safer.

  9. silverwind commented on Feb 6, 2015

    @silverwind
    silverwind
    on Feb 6, 2015
    Contributor
    More actions

    Any opinions if the address field in the object should be called address or ip? I'm leaning more towards address for correctness, but @cjihrig suggested ip. Also, the docs usually call it address.

  10. cjihrig commented on Feb 6, 2015

    @cjihrig
    cjihrig
    on Feb 6, 2015
    Contributor
    More actions

    FWIW, I don't have a strong opinion. I just thought addresses.address seemed a little odd.

  11. bnoordhuis commented on Feb 6, 2015

    @bnoordhuis
    bnoordhuis
    on Feb 6, 2015
    Member
    More actions

    We call it address in most other places, e.g. socket.address().address.

  12. silverwind commented on Feb 6, 2015

    @silverwind
    silverwind
    on Feb 6, 2015
    Contributor
    More actions

    I'll put this up shortly for a PR, just have to test on OS X, as apparently my Windows machine isn't able to dns.lookup for an IPv6 (getting ENOENT), but dns.resolve6 strangely works. This is on v1.x too. Might be a separate issue.

  13. cjihrig commented on Feb 6, 2015

    @cjihrig
    cjihrig
    on Feb 6, 2015
    Contributor
    More actions

    Thanks! Landed in eb30009de65a9432b59ae77a425b623df28dbd27 with a tweaked commit message.

    EDIT: Someone performed a force push after I landed this. So the mentioned commit was overwritten. The actual commit is now 633a990

  14. cjihrig
    closed this as completedon Feb 6, 2015
  15. cjihrig
    added a commit that references this issue on Feb 6, 2015

    dns: allow dns.lookup() to return all addresses

    633a990
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.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.