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

Fuzz IP.Is<property>() methods against stdlib net.IP equivalents #182

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ func Fuzz(b []byte) int {
fmt.Println("ip=", ip, "stdip=", stdip)
panic("net.IP.String() != IP.String()")
}

for _, tt := range []struct {
name string
ipResult bool
stdipResult bool
}{
{"IsInterfaceLocalMulticast", ip.IsInterfaceLocalMulticast(), stdip.IsInterfaceLocalMulticast()},
{"IsLinkLocalMulticast", ip.IsLinkLocalMulticast(), stdip.IsLinkLocalMulticast()},
{"IsLinkLocalUnicast", ip.IsLinkLocalUnicast(), stdip.IsLinkLocalUnicast()},
{"IsLoopback", ip.IsLoopback(), stdip.IsLoopback()},
{"IsMulticast", ip.IsMulticast(), stdip.IsMulticast()},
} {
if tt.ipResult != tt.stdipResult {
fmt.Printf("net.IP=%#v .%v=%v, netaddr.IP=%#v %v=%v\n", stdip, tt.name, tt.stdipResult, ip, tt.name, tt.ipResult)
panic(fmt.Sprintf(".%v() did not agree with stdlib", tt.name))
}
}
}
// Check that .Next().Prior() and .Prior().Next() preserve the IP.
if !ip.IsZero() && !ip.Next().IsZero() && ip.Next().Prior() != ip {
Expand Down