You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 25, 2023. It is now read-only.
There is Unmap to turn a 4in6 IPv6 into an IPv4, but there is no way to do the other way around.
This showed up when I was developing a library that has to accept both as the same, but the only way I found to do this conversion was through the standard library with netaddr.FromStdIP(ip.IPAddr().IP.To16()). This is horrible since it does 2 separate allocations to do what could be just an assignment.
I searched for any way to do this and the only thing I found was a mention that this wasn't yet implemented back in 2020.
The text was updated successfully, but these errors were encountered:
The netaddr package is now deprecated. You should use net/netip in the standard library instead, and https://pkg.go.dev/go4.org/netipx for the bits of this netaddr package that didn't make it into net/netip yet.
As for your question, use netaddr.IPv6Raw(ip.As16()) which doesn't allocate.
There is
Unmap
to turn a 4in6 IPv6 into an IPv4, but there is no way to do the other way around.This showed up when I was developing a library that has to accept both as the same, but the only way I found to do this conversion was through the standard library with
netaddr.FromStdIP(ip.IPAddr().IP.To16())
. This is horrible since it does 2 separate allocations to do what could be just an assignment.I searched for any way to do this and the only thing I found was a mention that this wasn't yet implemented back in 2020.
The text was updated successfully, but these errors were encountered: