From e0e0ea7aa8f56c3837cb13307e2a87908667f5d6 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 30 Jan 2013 15:08:04 -0700 Subject: [PATCH] fix IP checksum routine, finally --- netarch/ip.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/netarch/ip.py b/netarch/ip.py index 6357977..309e025 100644 --- a/netarch/ip.py +++ b/netarch/ip.py @@ -232,9 +232,7 @@ class TCP_Recreate(object): dip) shorts = struct.unpack('!HHHHHHHHHH', iphdr) shsum = sum(shorts) - shsum += shsum >> 16 # the carry - shsum = ~shsum # one's compliment - ipsum = struct.pack('!H', shsum & 0xffff) + ipsum = struct.pack('!H', ((shsum + (shsum >> 16)) & 0xffff) ^ 0xffff) iphdr = iphdr[:10] + ipsum + iphdr[12:] tcphdr = struct.pack('!HHLLBBHHH',