diff --git a/scapy/fields.py b/scapy/fields.py index 21314afd195bb3166ee21d7a50abb1526864996a..937b101d949744e87ae1e98cdf8e53d639de5f39 100644 --- a/scapy/fields.py +++ b/scapy/fields.py @@ -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): diff --git a/test/regression.uts b/test/regression.uts index de08b888f9dbb8f2ec2286d9ab05f0f3d0d81868..55b9ae9d1441649f7f6f5f13faed5ef14e741204 100644 --- a/test/regression.uts +++ b/test/regression.uts @@ -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 + ############ ############