diff --git a/ip.py b/ip.py index e4832a1..02acd1e 100644 --- a/ip.py +++ b/ip.py @@ -213,9 +213,9 @@ class TCP_Recreate: 0, # Header checksum sip, dip) - shorts = struct.unpack('!hhhhhhhhhh', iphdr) + shorts = struct.unpack('!HHHHHHHHHH', iphdr) shsum = sum(shorts) - ipsum = struct.pack('!h', (~shsum & 0xffff) - 2) # -2? WTF? + ipsum = struct.pack('!H', ((shsum + (shsum >> 16)) & 0xffff) ^ 0xffff) iphdr = iphdr[:10] + ipsum + iphdr[12:] tcphdr = struct.pack('!HHLLBBHHH',