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

Commit

Permalink
Fuzz IP.Is<property>() methods against stdlib net.IP equivalents
Browse files Browse the repository at this point in the history
The intent is to find discrepancies between netaddr.IP and net.IP. These
don't necessarily indicate a bug (in either), but it's better to find
them and explicitly document/exclude them.
  • Loading branch information
moreati committed May 24, 2021
1 parent d57edf1 commit a452640
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,29 @@ func Fuzz(b []byte) int {
panic(".Prior.Next did not round trip")
}

// Check that we agree with the standard library wrt to poperties
if !strings.Contains(s, "%") {
stdip := net.ParseIP(s)
tests := []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()},
}

for _, tt := range tests {
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))
}
}
}

port, err := ParseIPPort(s)
if err == nil {
checkStringParseRoundTrip(port, parseIPPort)
Expand Down

0 comments on commit a452640

Please sign in to comment.