Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
net: IP.To4 retains reference to IPv6 IP #10104
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.