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: cgoLookupAddrPTR returns single PTR regardless of number of PTR records #17093

Closed
DominoTree opened this issue Sep 13, 2016 · 6 comments
Closed
Labels
Documentation FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@DominoTree
Copy link

I've looked around at this and I'm pretty sure this is a bug with how the Cgo implementation gets PTR records using getnameinfo versus the native Go implementation.

What version of Go are you using (go version)?

go version go1.7.1 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/nxp6336/Projects/Go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.1/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/hr/sptqjvgs6g9580rch5z5c81c0000gn/T/go-build396826714=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

net.LookupAddr("138.12.4.174") or any other IP that has multiple PTR records

What did you expect to see?

Multiple hostnames returned

What did you see instead?

Only one hostname returned when using Cgo. By setting CGO_ENABLED=0, the native Go implementation is used instead, and multiple PTR records are returned as expected.

@DominoTree DominoTree changed the title cgoLookupAddrPTR returns single PTR regardless of number of PTR records net: cgoLookupAddrPTR returns single PTR regardless of number of PTR records Sep 14, 2016
@bradfitz bradfitz added this to the Go1.8 milestone Sep 14, 2016
@bradfitz
Copy link
Contributor

/cc @ianlancetaylor

@bradfitz bradfitz modified the milestones: Go1.8Maybe, Go1.8 Sep 14, 2016
@ianlancetaylor
Copy link
Contributor

I'm not sure what to do about this. The cgo code does a PTR lookup by calling the C function getnameinfo, which is the usual way to the name corresponding to an IP address. getnameinfo only returns a single answer. Is there a standard C interface that returns multiple PTR records?

@DominoTree
Copy link
Author

DominoTree commented Sep 14, 2016

Just to add some more thoughts here - as an end-user, the frustrating part for me wasn't really the ability to get multiple records. What frustrated me was the fact that the documentation states that I should receive multiple records for this call, and the default behavior will only return one.

LookupAddr performs a reverse lookup for the given address, returning a list of names mapping to that address.

The other really fun part of this is that (at least) BIND9 will return record results for a query in a random order. This means that if LookupAddr only returns one name, if you query the same IP repeatedly, if it has multiple PTRs, you'll get a different single result each time.

@bradfitz
Copy link
Contributor

At minimum we could document the situation I suppose.

@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 10, 2016
@rsc
Copy link
Contributor

rsc commented Oct 20, 2016

@bradfitz, it looks to me like we should document LookupAddr with something like

// LookupAddr performs a reverse lookup for the given address, returning a list
// of names mapping to that address.
//
// When using the host C library resolver, at most one result will be returned.
// To bypass the host resolver, use a custom Resolver. 
func LookupAddr(addr string) (names []string, err error) {

but that requires actually making (*Resolver).LookupAddr respect PreferGo, which it does not today. I filed #17532 for that.

@bradfitz bradfitz self-assigned this Oct 22, 2016
@gopherbot
Copy link

CL https://golang.org/cl/31720 mentions this issue.

@golang golang locked and limited conversation to collaborators Oct 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants