Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: add (*Resolver).ResolveIPAddr #30452

Open
iangudger opened this issue Feb 28, 2019 · 8 comments

Comments

Projects
None yet
6 participants
@iangudger
Copy link
Contributor

commented Feb 28, 2019

In the net package, there are two classes of DNS functions: LookupXxx and ResolveXxx. The net.Resolver type implements the LookupXxx functions as methods, but not the ResolveXxx functions. The ResolveXxx functions are similar to LookupHost, except they allow specifying a network. Adding the ResolveXxx functions as methods will allow a net.Resolver to fully replace the global DNS functions.

@gopherbot gopherbot added this to the Proposal milestone Feb 28, 2019

@gopherbot gopherbot added the Proposal label Feb 28, 2019

@bcmills

This comment has been minimized.

Copy link
Member

commented Feb 28, 2019

@bradfitz

This comment has been minimized.

Copy link
Member

commented Feb 28, 2019

I'm fine with that on principle. I'd never noticed you couldn't do IPv4- vs IPv6-specific lookups on Resolver before. That is, you can't do the equivalent of this today on Resolver:

func main() {
        fmt.Println(net.ResolveIPAddr("ip4", "google.com"))
        fmt.Println(net.ResolveIPAddr("ip6", "google.com"))
}

The name Resolver.ResolveIPAddr is a bit stuttery but probably best for consistency. But I'd also be fine with Resolver.LookupNetIPAddr or something.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Mar 6, 2019

It's unclear why we should add net.Resolver.ResolveIPAddr; why not just use LookupIPAddr and filter out what you want? ResolveIPAddr is just LookupIPAddr plus client-side filtering anyway. It's not any fewer bits on the wire.

@iangudger

This comment has been minimized.

Copy link
Contributor Author

commented Mar 6, 2019

Sure, it can be done, but it would be nice to not make everyone who wants it re-implement it.

@bradfitz

This comment has been minimized.

Copy link
Member

commented Mar 27, 2019

I'm inclined to add this. @rsc, it is fewer bytes on the wire, in both directions: only asking for A or AAAA instead of both, and only getting answers for what we asked for.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Apr 24, 2019

Today we have:

func (r *Resolver) LookupIPAddr(ctx context.Context, host string) ([]IPAddr, error)

We need a new name for the function that takes a network. It would be good to keep the Lookup prefix common to all the other methods.

Maybe it would be enough to shorten to "LookupIP":

func (r *Resolver) LookupIP(ctx context.Context, net, host string) ([]IPAddr, error)

where net is either "ip4" or "ip6".

Do we really need IPAddr in the return type vs plain IP? Can DNS return a zone?

@rsc

This comment has been minimized.

Copy link
Contributor

commented May 7, 2019

@iangudger, any thoughts on the questions in the previous comment? If that API is OK then I think we're close to accepting the proposal. Thanks for your help and your patience.

@iangudger

This comment has been minimized.

Copy link
Contributor Author

commented May 7, 2019

Sounds good to me.

@andybons andybons changed the title proposal: net: add (*Resolver).ResolveIPAddr net: add (*Resolver).ResolveIPAddr May 14, 2019

@andybons andybons modified the milestones: Proposal, Go1.14 May 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.