简体   繁体   中英

Adding PTPv2 layer to scapy

I want to add a PTPv2 Layer to scapy (v2.3.3) in python (v2.7). I added the ptpv2 class with the PTP entries to the file /scapy/layers/inet.py (because PTP is at layer 4). I also bound the ptpv2 layer to the upper layer, in my case Ethernet.

bind_layers(Ethernet,ptpv2)

By typing the scapy command "ls()" the created ptpv2 layer is listed, ok, success. But by accessing the layer through the python commands

for packet in PcapReader('/media/sf_SharedFolder/test.pcap'):
  if packet[ptpv2].sequenceId == anything:
    # do sth

the following error occurs:

File "/usr/lib/python2.7/dist-packages/scapy/packet.py", line 817, in __getitem__
  raise IndexError("Layer [%s] not found" % lname)
IndexError: Layer [ptpv2] not found

The Wireshark file has the layers Frame -> Ethernet -> PTP, so my binding command has to be right.

Don't know where the error is.

Pls, help me!

Thx

Chris

Your dissector is probably failing, but Scapy hides that and decodes the layer as Raw() .

You can:

  • check that by checking that packet.payload is a Raw instance.
  • try to find what crashes in your dissector by setting conf.debug_dissector = True .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM