net/netip: Document of AddrFromSlice
doesn't mention that passing IPv4 net.IP
made with net.ParseIP
to AddrFromSlice
creates IPv4 mapped IPv6 netip.Addr
#54826
Labels
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/Dnz95xrGio-
What did you expect to see?
What did you see instead?
The issue happens because
net.IP
holds an IPv4 address in the form of an IPv4 mapped IPv6 address if I understand correctly. SinceAddrFromSlice
is not aware of thenet.IP
and it only sees the length of the slice, so it is working as intended in that sense. However, the document ofAddrFromSlice
is a bit misleading.It can be read like we can use
AddrFromSlice
to convertnet.IP
tonetip.Addr
, but as mentioned in the #37921,net.IP
cannot distinguish IPv4 address and IPv4 mapped IPv6 address. Thus, users should always be aware of the address family ofnet.IP
before callingAddrFromSlice
and need to donet.IP.To4()
when it is an IPv4 address. I think users should know this.The text was updated successfully, but these errors were encountered: