I try to create a protocol, and I have some understanding problems. I created a class for every layer. Then I created some methods that build the packets for me, by stacking the layers one above the other.
When I create a packet:
a=Foo()/Bar() (or a=test())
I get something like:
<Foo | <Bar |>>
, this means, to my understanding that the
packets are encapsulated (like for example IP()/ICMP()
where it makes
sense). Now, my problem is that I want to have something more like:
<Foo |> <Bar |>
what am I doing wrong? Here follows the code I use (simplified version):
#!/usr/bin/env python
import logging
logging.getLogger("scapy").setLevel(1)
from scapy.all import *
class Foo(Packet):
name = "Foo packet"
fields_desc = [
ByteField("foo1", 0x23)
]
class Bar(Packet):
name = "Bar packet"
fields_desc = [
ByteField("bar1", 0x42)
]
def test():
a=Foo()
b=Bar()
return a/b
if __name__ == "__main__":
interact(mydict=globals(), mybanner="test-env")
Now, I'm not sure if "/" is the correct operator for this case. How would I do it in a better way? In my protocol the layers are independent and not encapsulated.