0

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Martin
  • 143
  • 2
  • 7

1 Answers1

2

If you don't want Bar inside Foo, I don't understand why you aren't using a list... for instance this is a list of two pings to 10.2.2.2... [IP(dst="10.2.2.2") / ICMP(), IP(dst="10.2.2.2") / ICMP()]

sr([IP(dst="10.2.2.2") / ICMP(), IP(dst="10.2.2.2") / ICMP()])
Begin emission:
........................*Finished to send 2 packets.
......*
Received 32 packets, got 2 answers, remaining 0 packets
(<Results: TCP:0 UDP:0 ICMP:2 Other:0>, <Unanswered: TCP:0 UDP:0 ICMP:0 Other:0>)
>>

Or in your case... return [a, b]. This would provide two distinct encapsulations, instead of them stacked in a protocol hierarchy

Mike Pennington
  • 41,899
  • 19
  • 136
  • 174