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

Commit 0bd5eca

Browse files
committed
Fuzz IP.Is<property>() methods against stdlib net.IP equivalents
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. Signed-off-by: Alex Willmer <alex@moreati.org.uk>
1 parent d57edf1 commit 0bd5eca

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

fuzz.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ func Fuzz(b []byte) int {
3232
fmt.Println("ip=", ip, "stdip=", stdip)
3333
panic("net.IP.String() != IP.String()")
3434
}
35+
36+
for _, tt := range []struct {
37+
name string
38+
ipResult bool
39+
stdipResult bool
40+
}{
41+
{"IsInterfaceLocalMulticast", ip.IsInterfaceLocalMulticast(), stdip.IsInterfaceLocalMulticast()},
42+
{"IsLinkLocalMulticast", ip.IsLinkLocalMulticast(), stdip.IsLinkLocalMulticast()},
43+
{"IsLinkLocalUnicast", ip.IsLinkLocalUnicast(), stdip.IsLinkLocalUnicast()},
44+
{"IsLoopback", ip.IsLoopback(), stdip.IsLoopback()},
45+
{"IsMulticast", ip.IsMulticast(), stdip.IsMulticast()},
46+
} {
47+
if tt.ipResult != tt.stdipResult {
48+
fmt.Printf("net.IP=%#v .%v=%v, netaddr.IP=%#v %v=%v\n", stdip, tt.name, tt.stdipResult, ip, tt.name, tt.ipResult)
49+
panic(fmt.Sprintf(".%v() did not agree with stdlib", tt.name))
50+
}
51+
}
3552
}
3653
// Check that .Next().Prior() and .Prior().Next() preserve the IP.
3754
if !ip.IsZero() && !ip.Next().IsZero() && ip.Next().Prior() != ip {

0 commit comments

Comments
 (0)