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: IP.To4() in package net is not returning nil for IPv6 address. #15529

Closed
kspessard opened this issue May 3, 2016 · 2 comments
Closed

net: IP.To4() in package net is not returning nil for IPv6 address. #15529

kspessard opened this issue May 3, 2016 · 2 comments
Milestone

Comments

@kspessard
Copy link

@kspessard kspessard commented May 3, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go version go1.6 linux/amd64
  2. What operating system and processor architecture are you using (go env)?
    GOARCH="amd64"
    GOBIN=""
    GOEXE=""
    GOHOSTARCH="amd64"
    GOHOSTOS="linux"
    GOOS="linux"
    GOPATH="/usr/local/google/home/kspessard/Go"
    GORACE=""
    GOROOT="/usr/lib/google-golang"
    GOTOOLDIR="/usr/lib/google-golang/pkg/tool/linux_amd64"
    GO15VENDOREXPERIMENT="1"
    CC="gcc"
    GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -gno-record-gcc-switches -fdebug-prefix-map=/tmp/go-build103771964=/tmp/go-build"
    CXX="g++"
    CGO_ENABLED="1"
  3. What did you do?
    https://play.golang.org/p/uKxvfsPPvu
  4. What did you expect to see?
    Since function ip.To4() is supposed to return nil if ip is IPv6, I expected to see....
    address 2001:abc:abc::/128 is IPv6    <------  This is correct.
    address 1.1.1.1/32 is IPv4
  1. What did you see instead?
    address 2001:abc:abc::/128 is IPv4    <------  This is incorrect.
    address 1.1.1.1/32 is IPv4
@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented May 3, 2016

/cc @mikioh

@bradfitz bradfitz added this to the Unplanned milestone May 3, 2016
@dominikh

This comment has been minimized.

Copy link
Member

@dominikh dominikh commented May 3, 2016

if ip.To4 != nil should be if ip.To4() != nil. You're comparing a function value against nil, not the return value of the function.

In the future please run go vet on your code to make sure it doesn't have such mistakes. Your Println calls should also be Printf calls.

@bradfitz bradfitz closed this May 3, 2016
@mikioh mikioh changed the title IPto4() in package net is not returning nil for IPv6 address. net: IP.To4() in package net is not returning nil for IPv6 address. Jul 22, 2016
@golang golang locked and limited conversation to collaborators Jul 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.