Scapy’s NBytesField endianness


This Content is from Stack Overflow. Question asked by Jeff Lieu

I”m making some new protocol that requires a 12-byte integer field. I cant find any information regarding the endianness of this field or some example of what this field is designed for.

class TestClass(Packet):
    name = "test"
    fields_desc = [
        NBytesField("data", 0, 12)  #12 byte long with 0 as default
###[ test ]### 
  data      = 2475880078570760549798248448

Raw(a) gives me what I expect, data as integer in big-endian.

>>> b'x00x00x00x00x00x00x00x00x00x00x00x08' also gives me correct value:


So the packet is created with data field in big-endian which is correct and that’s exactly what I want.

However when decoding a raw packet, it gives me wrong integer value.

>>> b=TestClass(raw(a))
>>> raw(b)

I can do some manipulation to convert it back.

But it’s seems strange that scapy encodes it with big-endian but then decodes it with little endian.

It’s just super weird. I don’t know what I’m missing here.

Thanks a lot!!!

I don’t have any problems if data is IntField


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?