Fix IP hash
authorSuperQ <superq@gmail.com>
Sat, 22 Jan 2022 15:37:30 +0000 (16:37 +0100)
committerSuperQ <superq@gmail.com>
Sat, 22 Jan 2022 15:37:30 +0000 (16:37 +0100)
Select the correct slice of bytes to hash based on IPv4 or IPv6 address
family.

Signed-off-by: SuperQ <superq@gmail.com>
prober/utils.go

index 74fb41d87ed5ea7ded7de61c06c360d78f4092f5..52f9f343f4ab21c364644ecf25e8db6dc564ac64 100644 (file)
@@ -135,6 +135,10 @@ func chooseProtocol(ctx context.Context, IPProtocol string, fallbackIPProtocol b
 
 func ipHash(ip net.IP) float64 {
        h := fnv.New32a()
-       h.Write(ip)
+       if ip.To4() != nil {
+               h.Write(ip.To4())
+       } else {
+               h.Write(ip.To16())
+       }
        return float64(h.Sum32())
 }