fixed ip checksum

This commit is contained in:
pi-rho 2013-01-30 20:02:15 -06:00
parent 06a964a3a1
commit 48b398a45f
1 changed files with 4 additions and 2 deletions

View File

@ -230,9 +230,11 @@ class TCP_Recreate(object):
0, # Header checksum 0, # Header checksum
sip, sip,
dip) dip)
shorts = struct.unpack('!hhhhhhhhhh', iphdr) shorts = struct.unpack('!HHHHHHHHHH', iphdr)
shsum = sum(shorts) 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:] iphdr = iphdr[:10] + ipsum + iphdr[12:]
tcphdr = struct.pack('!HHLLBBHHH', tcphdr = struct.pack('!HHLLBBHHH',