I'm using the following piece of python
code to capture traffic and dump it to a .pcap
file:
from pcapy import open_live
p = open_live("eth0", 65535, 1, 0)
dumper = p.dump_open("./test.pcap")
while capturing:
(header, packet) = p.next()
dumper.dump(header, packet)
I'm actually running this in a thread, where capturing
is a threading.Event()
that is set to False
when I want to stop the capture (so it exits the loop and returns cleanly).
However, when I try to open the test.pcap
with wireshark, I get this message:
The capture file appears to have been cut short in the middle of a packet.
I sometimes see that there are a couple of packets missing at the end of the test.pcap
(I can debug that because I'm writing the intercepted packets in a .csv file). But, besides that, I think the pcap file is fine. This message is a bit annoying, though. I thought that it could be that I need to include some magic number to make wireshark
believe it's a wireshark capture or something like that. I found other questions of people getting this message because they don't close the capture cleanly (but as I said, I do (or do I need to explicitly close the file descriptor open by pcapy
? I couldn't find a method in the pcapy API that closes it). Also, I'm not capturing with wireshark, so it might be a different problem).
Does anybody know what is the message due to? Or, does anybody know how can I debug and find the cause that makes wireshark pop this message?
EDIT
Pcapy source code that closes dumper
here.