Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Commit

Permalink
netaddr: add initial well-known IP addresses
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Layher <[email protected]>
  • Loading branch information
mdlayher committed Apr 25, 2020
1 parent ec53dc8 commit fca7370
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
16 changes: 16 additions & 0 deletions netaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import (
"strings"
)

// Well known IP addresses.
var (
IPv6LinkLocalAllNodes = mustIP("ff02::1")
IPv6Unspecified = mustIP("::")
)

// Sizes: (64-bit)
// net.IP: 24 byte slice header + {4, 16} = 28 to 40 bytes
// net.IPAddr: 40 byte slice header + {4, 16} = 44 to 56 bytes + zone length
Expand Down Expand Up @@ -584,3 +590,13 @@ func (p IPPrefix) Contains(addr IP) bool {
func (p IPPrefix) String() string {
return fmt.Sprintf("%s/%d", p.IP, p.Bits)
}

// mustIP parses s as an IP or panics.
func mustIP(s string) IP {
ip, err := ParseIP(s)
if err != nil {
panic(err)
}

return ip
}
9 changes: 0 additions & 9 deletions netaddr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,15 +685,6 @@ func TestParseIPPrefixError(t *testing.T) {
}
}

func mustIP(s string) IP {
ip, err := ParseIP(s)
if err != nil {
panic(err)
}

return ip
}

func mustIPs(strs ...string) []IP {
var res []IP
for _, s := range strs {
Expand Down

0 comments on commit fca7370

Please sign in to comment.