I have a some pcap files that I need to extract some information from, those packets are mixed, some are Raw IP and others contains ethernet frames.
I need to conditionally check for the type of packet before parsing as the packets with ethernet frames could be parsed with:
for ts, buf in pkts:
if buf contains_ethernet:
eth = dpkt.ethernet.Ethernet(buf)
if eth.type == dpkt.ethernet.ETH_TYPE_IP:
ip = eth.data
else:
continue
else:
ip = dpkt.ip.IP(buf)
How can I define the contains_ethernet
as a boolean or a condition?