Skip to content

Commit

Permalink
Add more error checking while reading a pcap file
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Fingerhut <andy_fingerhut@alum.wustl.edu>
  • Loading branch information
jafingerhut committed Feb 17, 2025
1 parent 31d80bb commit 262c48b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ptf/pcap_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def rdpcap_one_packet(f, ppi_len, return_packet_metadata):
if return_packet_metadata:
return None, None, None, None, None
return None
assert len(pkt_header_bytes) == PcapPktHeader.size
pkt_header = PcapPktHeader.unpack(pkt_header_bytes)
(
timestamp_sec,
Expand All @@ -101,6 +102,7 @@ def rdpcap_one_packet(f, ppi_len, return_packet_metadata):
) = pkt_header
# Consider supporting linktype LINKTYPE_PPI for reading.
pkt_data = f.read(caplength)
assert len(pkt_data) == caplength
if return_packet_metadata:
return pkt_data, timestamp_sec, timestamp_micro, caplength, length
return pkt_data
Expand Down

0 comments on commit 262c48b

Please sign in to comment.