chiark / gitweb /
Iteratively ones-c the checksum
[vinegar-ip.git] / make-probes.tcl
index a23edff8bf7d816b7011e26e365938c1489e023c..3466cdbc63ad8d865f6bdad6b240743b9cc9baaa 100755 (executable)
@@ -49,7 +49,10 @@ proc packet-csum-ip {packet} {
        set cs [expr "\$cs + 0x$this"]
        debug 7 [format "0x%s 0x%08x" $this $cs]
     }
-    return [expr {(($cs & 0xffff) + (($cs >> 16) & 0xffff)) ^ 0xffff}]
+    while {$cs > 0xffff} {
+       set cs [expr {($cs & 0xffff) + (($cs >> 16) & 0xffff)}]
+    }
+    return [expr {$cs ^ 0xffff}]
 }
 
 proc packet-fromstring {s} {