From 2ab42e81ff959e31d846e6b2f7dc33fa9414042b 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 --- ip.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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',