net/packet: documentation pass.

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson
2020-11-10 22:26:00 -08:00
parent c2cc3acbaf
commit a38e28da07
6 changed files with 116 additions and 83 deletions

View File

@ -10,8 +10,10 @@ import (
"inet.af/netaddr"
)
// IP6 is an IPv6 address.
type IP6 [16]byte
// 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))
@ -19,6 +21,7 @@ func IP6FromNetaddr(ip netaddr.IP) IP6 {
return IP6(ip.As16())
}
// Netaddr converts ip to a netaddr.IP.
func (ip IP6) Netaddr() netaddr.IP {
return netaddr.IPFrom16(ip)
}
@ -27,4 +30,5 @@ func (ip IP6) String() string {
return ip.Netaddr().String()
}
// ip6HeaderLength is the length of an IPv6 header with no IP options.
const ip6HeaderLength = 40