use std::time::Duration;
use netring::export::JsonFlowExporter;
use netring::monitor::Monitor;
use netring::protocol::builtin::Tcp;
#[tokio::main]
async fn main() -> Result<(), netring::Error> {
let iface = std::env::args().nth(1).unwrap_or_else(|| "lo".to_string());
let monitor = Monitor::builder()
.interface(&iface)
.protocol::<Tcp>()
.export_flows(JsonFlowExporter::stdout())
.export_active_timeout(Duration::from_secs(30))
.export_flows(|rec: &netring::export::FlowRecord| {
if rec.is_ongoing() {
eprintln!(
"# ongoing {:?} {} ↔ {} : {} bytes so far",
rec.proto,
rec.a,
rec.b,
rec.total_bytes()
);
}
})
.build()?;
println!("# exporting TCP flow records on {iface} (Ctrl-C to stop)");
monitor.run_until_signal().await
}