From 48b398a45fb5814188aebcaf3dbda21d39e147ce Mon Sep 17 00:00:00 2001 From: pi-rho Date: Wed, 30 Jan 2013 20:02:15 -0600 Subject: [PATCH] fixed ip checksum --- netarch/ip.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/netarch/ip.py b/netarch/ip.py index 1d703f8..28be66d 100644 --- a/netarch/ip.py +++ b/netarch/ip.py @@ -230,9 +230,11 @@ class TCP_Recreate(object): 0, # Header checksum sip, dip) - shorts = struct.unpack('!hhhhhhhhhh', iphdr) + shorts = struct.unpack('!HHHHHHHHHH', iphdr) shsum = sum(shorts) - ipsum = struct.pack('!H', (~shsum & 0xffff)) + shsum += shsum >> 16 # the carry + shsum = ~shsum # one's compliment + ipsum = struct.pack('!H', shsum & 0xffff) iphdr = iphdr[:10] + ipsum + iphdr[12:] tcphdr = struct.pack('!HHLLBBHHH',