From 1ab1cd44d3edd215949384b65342d63c2f46a1a4 Mon Sep 17 00:00:00 2001
From: gpotter2 <gabriel@potter.fr>
Date: Fri, 11 Aug 2017 10:23:38 +0200
Subject: [PATCH] Fix little-big endian dissection issue

---
 scapy/fields.py     | 6 ++++--
 test/regression.uts | 6 ++++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/scapy/fields.py b/scapy/fields.py
index 21314afd..937b101d 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 de08b888..55b9ae9d 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
+
 
 ############
 ############
-- 
GitLab