socket_filter

Crates.iosocket_filter
lib.rssocket_filter
version0.2.2
sourcesrc
created_at2024-09-27 12:51:11.382578
updated_at2024-10-23 08:11:09.977543
descriptionA simple bpf program to monitor host's net traffic
homepagehttps://github.com/arloor/bpf_rs_hub/tree/master/socket_filter
repositoryhttps://github.com/arloor/bpf_rs_hub
max_upload_size
id1388639
size2,530,649
(arloor)

documentation

README

use epbf program type BPF_PROG_TYPE_SOCKET_FILTER to monitor the network traffic of the host.

Example

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));
    }
}

Commit count: 103

cargo fmt