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: LookupIP("127.0.0.1") does not work when CGO_ENABLED=1 #11335

Closed
neild opened this issue Jun 22, 2015 · 7 comments
Closed

net: LookupIP("127.0.0.1") does not work when CGO_ENABLED=1 #11335

neild opened this issue Jun 22, 2015 · 7 comments
Milestone

Comments

@neild
Copy link
Contributor

neild commented Jun 22, 2015

package main
import (
        "fmt"
        "net"
)
func main() {
        fmt.Println(net.LookupIP("127.0.0.1"))
}
$ go version
go version go1.4.2 linux/amd64
$ go run main.go
[127.0.0.1] <nil>

$ /tmp/g/go version
go version devel +e38bcb5 Wed Jun 17 18:17:50 2015 +0000 linux/amd64
$ /tmp/g/go run main.go
[] lookup 127.0.0.1: invalid domain name

$ uname -a
Linux kinoko.mtv.corp.google.com 3.13.0-52-generic #86-Ubuntu SMP Mon May 4 04:32:59 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

The net.LookupIP docs are unclear on what it does with IPs as opposed to hostnames, but changing the behavior seems wrong.

@mikioh mikioh changed the title net: LookupIP("127.0.0.1") does not work with 1.5 net: LookupIP("127.0.0.1") does not work when CGO_ENABLED=1 Jun 22, 2015
@mikioh mikioh added this to the Go1.5 milestone Jun 22, 2015
@mikioh
Copy link
Contributor

mikioh commented Jun 22, 2015

I think this is expected behavior from go1.5, and a consequence of the new feature described in 4a0ba7a.

@bradfitz
Copy link
Contributor

@ianlancetaylor, @rsc, any opinions on this? Apparently glibc lets you do a DNS lookup on an IP address? Is that part of the net.LookupIP contract? Do we care if this behavior changes?

@rsc
Copy link
Contributor

rsc commented Jun 23, 2015

It wasn't intended but I think it's probably worth keeping.

@rsc
Copy link
Contributor

rsc commented Jun 23, 2015

That is, we should keep the 1.4 behavior.

@bradfitz
Copy link
Contributor

Easy enough. I assume we can just recognize IP literals (IPv4 or IPv6) and return them immediately, without regard to the system's nsswitch.conf or resolv.conf, etc. I hope that glibc isn't doing anything fancier? @mikioh, do you know?

@ianlancetaylor
Copy link
Contributor

That is what glibc's getaddrinfo function does: it calls inet_aton on the name, and, if that succeeds, returns the result.

@gopherbot
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants