From 2e4e7c7c07f4730b1275c35daa71df7a2c377c19 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Fri, 29 Dec 2023 01:20:06 +0200 Subject: [PATCH] parses all packets, forgot to account for partial --- thermalcamdecoder/src/main.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/thermalcamdecoder/src/main.rs b/thermalcamdecoder/src/main.rs index 7818ece..2327b47 100644 --- a/thermalcamdecoder/src/main.rs +++ b/thermalcamdecoder/src/main.rs @@ -7,12 +7,24 @@ fn main() -> anyhow::Result<()> { let file = File::open("in.pcap")?; let mut cap = PcapNGReader::new(65535, file)?; let mut i = 0; - let mut max_offset = 0; - while let Ok((offset, _packet)) = cap.next() { - i += 1; - max_offset = offset; - cap.consume(offset) + let mut size = 0; + loop { + match cap.next() { + Ok((offset, _packet)) => { + i += 1; + size += offset; + cap.consume(offset) + } + Err(PcapError::Eof) => break, + Err(PcapError::Incomplete) => { + cap.refill().unwrap(); + } + Err(_) => { + println!("unexpected error"); + break; + } + } } - println!("found {} packets, {} last offset", i, max_offset); + println!("found {} packets, {} size", i, size); Ok(()) }