mirror of https://github.com/dirtbags/netarch.git
Correctly calculate payload length
This commit is contained in:
parent
3232991bc8
commit
5282669973
|
@ -47,11 +47,11 @@ class Frame:
|
||||||
self.th_sum,
|
self.th_sum,
|
||||||
self.th_urp,
|
self.th_urp,
|
||||||
p) = unpack("!HHLLBBHHH", p)
|
p) = unpack("!HHLLBBHHH", p)
|
||||||
(th_off, th_x2) = unpack_nybbles(x2off)
|
(self.th_off, th_x2) = unpack_nybbles(x2off)
|
||||||
opt_length = th_off * 4
|
opt_length = self.th_off * 4
|
||||||
|
|
||||||
self.th_options = p[20:opt_length]
|
self.th_options, p = p[:opt_length - 20], p[opt_length - 20:]
|
||||||
payload = p[opt_length:self.tot_len - 40]
|
payload = p[:self.tot_len - opt_length - 20]
|
||||||
|
|
||||||
self.src = (self.saddr, self.th_sport)
|
self.src = (self.saddr, self.th_sport)
|
||||||
self.dst = (self.daddr, self.th_dport)
|
self.dst = (self.daddr, self.th_dport)
|
||||||
|
@ -120,11 +120,11 @@ class TCP_Session:
|
||||||
while True:
|
while True:
|
||||||
p = self.pc.read()
|
p = self.pc.read()
|
||||||
if not p:
|
if not p:
|
||||||
return
|
raise EOFError()
|
||||||
try:
|
try:
|
||||||
return Frame(p[1])
|
return Frame(p[1])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise
|
pass
|
||||||
|
|
||||||
def read_handshake(self):
|
def read_handshake(self):
|
||||||
# Read SYN
|
# Read SYN
|
||||||
|
@ -154,8 +154,9 @@ class TCP_Session:
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
pkt = self.read_packet()
|
pkt = self.read_packet()
|
||||||
if not pkt:
|
except EOFError:
|
||||||
return
|
return
|
||||||
self.frames += 1
|
self.frames += 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue