#[cfg(unix)]
use pcapture::Capture;
#[cfg(unix)]
use pcapture::PcapByteOrder;
#[cfg(unix)]
use pcapture::fs::pcapng::PcapNg;
#[cfg(unix)]
fn main() {
let path = "test.pcapng";
let pbo = PcapByteOrder::WiresharkDefault;
#[cfg(target_os = "linux")]
let mut cap = Capture::new("ens33").unwrap();
#[cfg(target_os = "freebsd")]
let mut cap = Capture::new("em0").unwrap();
#[cfg(target_os = "macos")]
let mut cap = Capture::new("en0").unwrap();
cap.set_filter("host 192.168.5.77");
let mut pcapng = cap.gen_pcapng_header(pbo).unwrap();
let h_len = pcapng.blocks.len();
let mut i = 0;
while i < 5 {
let blocks = cap.fetch_as_pcapng().unwrap();
for b in blocks {
pcapng.append(b);
i += 1;
}
}
pcapng.write_all(path).unwrap();
let read_pcapng = PcapNg::read_all(path, pbo).unwrap();
assert_eq!(read_pcapng.blocks.len(), h_len + i);
}
#[cfg(windows)]
fn main() {
println!("This example is disabled on Windows");
}