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 retains reference to IPv6 IP #10104

anacrolix opened this issue Mar 8, 2015 · 2 comments


None yet
4 participants
Copy link

commented Mar 8, 2015

Calling .To4 on an IPv6 IP, returns a slice of the IPv4 part of the address. Elsewhere new buffers are allocated instead, and it's natural to assume this is the case for To4 as well. User code can proceed assuming it now owns the contents of net.IP which is not correct.

To4 converts the IPv4 address ip to a 4-byte representation. If ip is not an IPv4 address, To4 returns nil. There is no guarantee the returned IP is freshly allocated.



This comment has been minimized.

Copy link

commented Mar 8, 2015


This comment has been minimized.

Copy link

commented Apr 10, 2015

This was intentional. You probably shouldn't modify IP addresses' slice data once created.

@rsc rsc closed this Apr 10, 2015

@golang golang locked and limited conversation to collaborators Jun 25, 2016

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