socket_filter 0.1.0

A simple bpf program to monitor host's net traffic
docs.rs failed to build socket_filter-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: socket_filter-0.2.3

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

Example

use std::{mem::MaybeUninit, thread::sleep, time::Duration};

fn main() {
    let open_object = Box::leak(Box::new(MaybeUninit::uninit())); // make the ebpf prog lives as long as the process.
    let socket_filter = socket_filter::TransmitCounter::new(
        &["lo", "podman", "veth", "flannel", "cni0", "utun"],
        open_object,
    );
    loop {
        println!(
            "current bytes: {} {}",
            socket_filter.get_egress(),
            socket_filter.get_ingress()
        );
        sleep(Duration::from_secs(1));
    }
}