0
votes

I'm trying to create my own protocol for scapy and have been stuck for the last couple of days.

What I'm looking to do is use the first 14 bytes for the first layer, 6 for dst mac, 6 src mac, 2 for padding. The rest of the packet would be the payload.

The problem is I'm not exactly sure how to make the 5th and 6th byte in the packet to be a field that would give an ShortField value.

class MyEther(Packet):

   name = "MyEther"

   fields_desc =[
          MACField("dst", None),
          MACField("src", None),
          StrLenField('padding', None, length_from=lambda x: 2)
   ]

help is much appreciated!

1
Hi ! What do you mean by "the 5th and 6th byte" ? In your layer, the 5 and 6 bytes are in the dst MACField :/Cukic0d
Exactly, I'm looking to read the 5 and 6 byte also as a short. These two bytes is representative as a port in my protocol.huynle

1 Answers

0
votes

In this case, the use of MACField is not appropriate. You should use an IntField followed by a ShortField, for each MACField.

fields_desc = [
    IntField(“a”, 0),
    ShortField(“b”, 0), # here are your 5-6 bytes
    ....
]

If you really know what you are doing, however, and you know you need MACField, you can use

struct.unpack(“!H”, mac2str(packet.dst)[4:6])

(mac2str is imported from scapy)