Posted to tcl by kbk at Thu Oct 22 16:48:24 GMT 2009view raw
- proc inet_cksum32_kbk2 {data} {
- binary scan $data Iu*cu* x extra
- lappend extra 0 0 0 0
- lassign $extra p q r s
- set sum [expr {($p << 24) + ($q << 16) + ($r << 8) + $s}]
- foreach w $x {
- incr sum $w
- }
- set sum [expr {($sum & 0xffffffff) + ($sum >> 32)}]
- set sum [expr {($sum & 0xffff) + ($sum >> 16)}]
- set sum [expr {($sum & 0xffff) + ($sum >> 16)}]
- return [expr {(-1-$sum) & 0xffff}]
- }