use async_pcap::{AsyncCapture, Capture, Device};
use tokio::runtime::Runtime;
fn main() {
let rt = Runtime::new().unwrap();
rt.block_on(async {
let device = Device::lookup().unwrap().unwrap();
let cap = Capture::from_device(device)
.unwrap()
.promisc(true)
.snaplen(65535)
.timeout(500)
.immediate_mode(true)
.open()
.unwrap();
let (async_cap, handle) = AsyncCapture::new(cap);
let handle_clone = handle.clone();
tokio::spawn(async move {
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
handle_clone.stop(); println!("Capture stopped from another task");
});
while let Some(packet) = async_cap.next_packet().await {
println!("Captured packet: {} bytes", packet.data.len());
}
println!("Capture loop exited cleanly");
});
}