Fix little-big endian dissection issue

This commit is contained in:
gpotter2 2017-08-11 10:23:38 +02:00
parent 695913c5ae
commit 1ab1cd44d3
2 changed files with 10 additions and 2 deletions

View File

@ -730,9 +730,11 @@ class BitField(Field):
self.size = abs(size)
def reverse(self, val):
if self.size == 16:
val = socket.ntohs(val)
# Replaces socket.ntohs (but work on both little/big endian)
val = struct.unpack('>H',struct.pack('<H', val))[0]
elif self.size == 32:
val = socket.ntohl(val)
# Same here but for socket.ntohl
val = struct.unpack('>I',struct.pack('<I', val))[0]
return val
def addfield(self, pkt, s, val):

View File

@ -643,6 +643,12 @@ assert(_ == b'\x00\x00\x00\x00\xe3OjYLw\xc3x_%\xd0\xcf\xdeu-\xc3pH#\x1eK\xae\xf5
Dot11WEP(_)
assert(TCP in _ and _[TCP].seq == 12345678)
= RadioTap Big-Small endian dissection
raw = b'\x00\x00\x1a\x00/H\x00\x00\xe1\xd3\xcb\x05\x00\x00\x00\x00@0x\x14@\x01\xac\x00\x00\x00'
r = RadioTap(raw)
r.show()
assert r.present == 18479
############
############