| Crates.io | socket_filter |
| lib.rs | socket_filter |
| version | 0.2.3 |
| created_at | 2024-09-27 12:51:11.382578+00 |
| updated_at | 2025-07-14 12:46:35.229683+00 |
| description | A simple bpf program to monitor host's net traffic |
| homepage | https://github.com/arloor/bpf_rs_hub/tree/master/socket_filter |
| repository | https://github.com/arloor/bpf_rs_hub |
| max_upload_size | |
| id | 1388639 |
| size | 2,541,512 |
use epbf program type BPF_PROG_TYPE_SOCKET_FILTER to monitor the network traffic of the host.
use std::mem::MaybeUninit;
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut open_object = MaybeUninit::uninit(); // make the ebpf prog lives as long as the process.
let socket_filter =
socket_filter::TransmitCounter::new(&mut open_object, socket_filter::IGNORED_IFACE)?;
loop {
println!(
"current bytes: {} {}",
socket_filter.get_egress(),
socket_filter.get_ingress()
);
std::thread::sleep(std::time::Duration::from_secs(1));
}
}