Attempting to read a pcap with Kaitai Struct in python.
I have created the python files from the pcap.ksy
file
$ ./bin/kaitai-struct-compiler -t python --outdir xx formats/network/pcap.ksy
$ ls xx
ethernet_frame.py ipv6_packet.py __pycache__
icmp_packet.py packet_ppi.py tcp_segment.py
ipv4_packet.py pcap.py udp_datagram.py
PYTHONPATH is set to the xx directory. Now if I run a simple one line script to check that I can load the modules
from pcap import Pcap
I get this error
$ python3 try.py
Traceback (most recent call last):
File "try.py", line 1, in <module>
from pcap import Pcap
File "/spare/tmp/scratch/kaitai-struct-compiler-0.8/xx/pcap.py", line 11, in <module>
from packet_ppi import PacketPpi
File "/spare/tmp/scratch/kaitai-struct-compiler-0.8/xx/packet_ppi.py", line 11, in <module>
from ethernet_frame import EthernetFrame
File "/spare/tmp/scratch/kaitai-struct-compiler-0.8/xx/ethernet_frame.py", line 11, in <module>
from ipv6_packet import Ipv6Packet
File "/spare/tmp/scratch/kaitai-struct-compiler-0.8/xx/ipv6_packet.py", line 12, in <module>
from ipv4_packet import Ipv4Packet
File "/spare/tmp/scratch/kaitai-struct-compiler-0.8/xx/ipv4_packet.py", line 13, in <module>
from ipv6_packet import Ipv6Packet
ImportError: cannot import name 'Ipv6Packet'
My reading of that is the python path is ok and the python modules are working their way down the chain from pacp, through Ethernet, ipv6 to ipv4. Then ipv4 attempts to load ipv6 again and the script falls over.
I think the code is triggering an import loop.
Anyone know what I'm doing wrong?
It's a circular dependency problem which only manifests in Python, and it is solved with a workaround in newer Kaitai Struct builds (0.9 unstable).
Please try updating to KS 0.9+.