art
art copied to clipboard
ipv4AsUint() does not consider IPv4-mapped-IPv6 addresses
// ipv4AsUint returns ip as a uint32.
func ipv4AsUint(ip netip.Addr) uint32 {
bs := ip.As4()
return binary.BigEndian.Uint32(bs[:])
}
One can argue about whether IPv4-mapped IPv6 addresses should be allowed as a prefix at all, but in the following code snippet you already pay attention to it:
func (t *Table[T]) Get(addr netip.Addr) (ret T, ok bool) {
t.init()
// Ideally we would use addr.AsSlice here, but AsSlice is just
// barely complex enough that it can't be inlined, and that in
// turn causes the slice to escape to the heap. Using As16 and
// manual slicing here helps the compiler keep Get alloc-free.
st := t.tableForAddr(addr)
rawAddr := addr.As16()
bs := rawAddr[:]
if addr.Is4() {
bs = bs[12:]
}
// ...
thanks for ART