Skip to content

Commit

Permalink
net/netip: add IPv6LinkLocalAllRouters and IPv6Loopback
Browse files Browse the repository at this point in the history
Fixes golang#51766
Fixes golang#51777

Change-Id: I0510175c20c06442d78b2581cfe218e66be1c35b
Reviewed-on: https://go-review.googlesource.com/c/go/+/412475
Auto-Submit: Brad Fitzpatrick <[email protected]>
Reviewed-by: David Chase <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
Run-TryBot: Brad Fitzpatrick <[email protected]>
Reviewed-by: Tobias Klauser <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Run-TryBot: Matt Layher <[email protected]>
Reviewed-by: Brad Fitzpatrick <[email protected]>
Auto-Submit: Damien Neil <[email protected]>
  • Loading branch information
mdlayher authored and romaindoumenc committed Nov 3, 2022
1 parent 5194e10 commit a55817e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/next/51766.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg net/netip, func IPv6LinkLocalAllRouters() Addr #51766
1 change: 1 addition & 0 deletions api/next/51777.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg net/netip, func IPv6Loopback() Addr #51777
7 changes: 7 additions & 0 deletions src/net/netip/netip.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ var (
// address ff02::1.
func IPv6LinkLocalAllNodes() Addr { return AddrFrom16([16]byte{0: 0xff, 1: 0x02, 15: 0x01}) }

// IPv6LinkLocalAllRouters returns the IPv6 link-local all routers multicast
// address ff02::2.
func IPv6LinkLocalAllRouters() Addr { return AddrFrom16([16]byte{0: 0xff, 1: 0x02, 15: 0x02}) }

// IPv6Loopback returns the IPv6 loopback address ::1.
func IPv6Loopback() Addr { return AddrFrom16([16]byte{15: 0x01}) }

// IPv6Unspecified returns the IPv6 unspecified address "::".
func IPv6Unspecified() Addr { return Addr{z: z6noz} }

Expand Down
12 changes: 12 additions & 0 deletions src/net/netip/netip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,16 @@ func TestAddrWellKnown(t *testing.T) {
ip: IPv6LinkLocalAllNodes(),
std: net.IPv6linklocalallnodes,
},
{
name: "IPv6 link-local all routers",
ip: IPv6LinkLocalAllRouters(),
std: net.IPv6linklocalallrouters,
},
{
name: "IPv6 loopback",
ip: IPv6Loopback(),
std: net.IPv6loopback,
},
{
name: "IPv6 unspecified",
ip: IPv6Unspecified(),
Expand Down Expand Up @@ -1867,6 +1877,8 @@ func TestNoAllocs(t *testing.T) {
test("ParseAddr/6", func() { sinkIP = panicIP(ParseAddr("::1")) })
test("MustParseAddr", func() { sinkIP = MustParseAddr("1.2.3.4") })
test("IPv6LinkLocalAllNodes", func() { sinkIP = IPv6LinkLocalAllNodes() })
test("IPv6LinkLocalAllRouters", func() { sinkIP = IPv6LinkLocalAllRouters() })
test("IPv6Loopback", func() { sinkIP = IPv6Loopback() })
test("IPv6Unspecified", func() { sinkIP = IPv6Unspecified() })

// IP methods
Expand Down

0 comments on commit a55817e

Please sign in to comment.