use std::env; use ethrecv::{PacketHandler, RecvThread}; #[derive(Debug)] enum AppError {} #[derive(Default)] struct PktProc {} impl PacketHandler for PktProc { type Error = AppError; fn proc(&mut self, _pkt: pcap::Packet) -> Result<(), Self::Error> { eprintln!("packet!"); Ok(()) } #[cfg(feature = "idle")] fn idle(&mut self) -> Result<(), Self::Error> { eprintln!("idle!"); Ok(()) } #[cfg(feature = "inspect")] fn inspect(&self, info: ðrecv::RecvInfo) { eprintln!("inspect!"); eprintln!("overflow drop: {}", info.overflow_dropped); eprintln!("if drop: {}", info.if_dropped); eprintln!("num raw pkts: {}", info.num_raw_pkts); eprintln!("raw pkt bytes: {}", info.raw_pkt_bytes); eprintln!("uptime: {:?}", info.runtime); } } fn main() { let args: Vec = env::args().skip(1).collect(); let rt = RecvThread::new(&args[0]); #[cfg(feature = "idle")] let rt = rt.idle_duration(std::time::Duration::from_secs(4)); let pp = PktProc::default(); #[cfg(feature = "inspect")] let mut ctrl = rt.run(pp).unwrap(); #[cfg(not(feature = "inspect"))] let ctrl = rt.run(pp).unwrap(); std::thread::sleep(std::time::Duration::from_secs(10)); #[cfg(feature = "inspect")] ctrl.signal_inspect().unwrap(); #[cfg(feature = "inspect")] { let stats = ctrl.inspect().unwrap(); println!("{stats:#?}"); } std::thread::sleep(std::time::Duration::from_secs(30)); #[cfg(feature = "inspect")] { let stats = ctrl.inspect().unwrap(); println!("{stats:#?}"); } println!("Killing receiver thread.."); ctrl.shutdown().unwrap(); } // vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :