Package: iftop
Version: 0.17-16
Severity: wishlist

The present implementation of hash algoritm for address pairs
suffers from a mistake in operator priorities. Thus the key space
is half as large as intended, and it has a significantly larger
proportion of collisions, since it in effect only uses the least
significant octets of source and destination addresses.

The patch included below can serve as documentation of this fact,
independently of any desire to apply the patch or not.

The upstream author simply forgot to take account of the higher
precedence for the operator '>>' in relation to that of '&'.


Regards,

Mats Erik Andersson, fil. dr

###########################################
--- iftop-0.17.debian/addr_hash.c
+++ iftop-0.17/addr_hash.c
@@ -26,16 +26,16 @@
     addr = (long)ap->src.s_addr;
 
     hash = ((addr & 0x000000FF)
-            + (addr & 0x0000FF00 >> 8)
-            + (addr & 0x00FF0000 >> 16)
-            + (addr & 0xFF000000 >> 24)
+            + ((addr & 0x0000FF00) >> 8)
+            + ((addr & 0x00FF0000) >> 16)
+            + ((addr & 0xFF000000) >> 24)
             + ap->src_port) % 0xFF;
 
     addr = (long)ap->dst.s_addr;
     hash = ( hash + (addr & 0x000000FF)
-            + (addr & 0x0000FF00 >> 8)
-            + (addr & 0x00FF0000 >> 16)
-            + (addr & 0xFF000000 >> 24)
+            + ((addr & 0x0000FF00) >> 8)
+            + ((addr & 0x00FF0000) >> 16)
+            + ((addr & 0xFF000000) >> 24)
             + ap->dst_port) % 0xFF;
 
     return hash;



-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to