mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-01 14:05:39 +00:00
net/packet: add an IP6 constructor from a raw byte array.
Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
f0b0a62873
commit
aa353b8d0f
@ -16,13 +16,17 @@ type IP6 struct {
|
||||
Hi, Lo uint64
|
||||
}
|
||||
|
||||
// IP6FromRaw16 converts a raw 16-byte IPv6 address to an IP6.
|
||||
func IP6FromRaw16(ip [16]byte) IP6 {
|
||||
return IP6{binary.BigEndian.Uint64(ip[:8]), binary.BigEndian.Uint64(ip[8:])}
|
||||
}
|
||||
|
||||
// IP6FromNetaddr converts a netaddr.IP to an IP6. Panics if !ip.Is6.
|
||||
func IP6FromNetaddr(ip netaddr.IP) IP6 {
|
||||
if !ip.Is6() {
|
||||
panic(fmt.Sprintf("IP6FromNetaddr called with non-v6 addr %q", ip))
|
||||
}
|
||||
b := ip.As16()
|
||||
return IP6{binary.BigEndian.Uint64(b[:8]), binary.BigEndian.Uint64(b[8:])}
|
||||
return IP6FromRaw16(ip.As16())
|
||||
}
|
||||
|
||||
// Netaddr converts ip to a netaddr.IP.
|
||||
|
Loading…
Reference in New Issue
Block a user