Nitay Nitay - 8 months ago 165
Python Question

dpkt throws NeedData on valid pcap

I have this python code:

import sys
import dpkt

f = file("pcaop.Pcap")
pcap = dpkt.pcap.Reader(f)

i = 0
for ts, buf in pcap:
print "Ya"

dpkt throws NeedData on the 52nd packet. The same one every time - I've checked packet 52 and it is the same as everyone else on wireshark.

What causes this?


Solution is provided here: Python stops reading file using read I had the same problem when dpkt.pcap was working fine under Linux but failed instantly when run in Windows. The problem is that when a file is opened in text mode open("filename", "r") the file is read until EOF is encountered. Thus, open("filename", "rb")