Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure unpack binary in byte size #147

Open
wants to merge 2 commits into
base: carp
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pox/lib/packet/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def to_bytes(self):
elif self.type == tcp_opt.SACKPERM:
return struct.pack('!BB',self.type,2)
elif self.type == tcp_opt.SACK:
return struct.pack("!" + "II" * len(self.val),
*[x for p in self.val for x in p])
return struct.pack("!BB" + "II" * len(self.val),
*([self.type, 2+8*len(self.val)] + [x for p in self.val for x in p]))
elif self.type == tcp_opt.TSOPT:
return struct.pack('!BBII',self.type,10,self.val[0],self.val[1])
else:
Expand Down Expand Up @@ -219,7 +219,7 @@ def parse_options(self, raw):
elif ord(arr[i]) == tcp_opt.SACK:
if ord(arr[i+1]) >= 2 and ((ord(arr[i+1])-2) % 8) == 0:
num = (ord(arr[i+1]) - 2) / 8
val = struct.unpack("!" + "II" * num, arr[i+2:])
val = struct.unpack("!" + "II" * num, arr[i+2:i+2+num*8])
val = [(x,y) for x,y in zip(val[0::2],val[1::2])]
self.options.append(tcp_opt(tcp_opt.SACK, val))
else:
Expand Down