#async

pcap-async

Async/Stream Extensions for libpcap

14 unstable releases (3 breaking)

0.4.1 Sep 30, 2020
0.3.0 Jul 2, 2020
0.2.1 Nov 12, 2020
0.1.5 Mar 29, 2020
0.1.3 Dec 19, 2019

#716 in Asynchronous

Download history 19/week @ 2023-10-22 42/week @ 2023-10-29 31/week @ 2023-11-05 36/week @ 2023-11-12 10/week @ 2023-11-19 76/week @ 2023-11-26 90/week @ 2023-12-03 60/week @ 2023-12-10 13/week @ 2023-12-17 35/week @ 2023-12-24 43/week @ 2023-12-31 27/week @ 2024-01-07 22/week @ 2024-01-14 21/week @ 2024-01-21 48/week @ 2024-01-28 15/week @ 2024-02-04

109 downloads per month

MIT license

62KB
1.5K SLoC

pcap-async

build status crates.io version docs.rs docs MIT licensed

Rust async wrapper around pcap-sys. Utilizes Futures 0.3 and Smol.

Documentation

Usage

First, add this to your Cargo.toml:

[dependencies]
pcap-async = "0.3"

Next, add this to your crate:

use futures::StreamExt;
use pcap_async::{Config, Handle, PacketStream};

fn main() {
    smol::run(async move {
        let handle = Handle::lookup().expect("No handle created");
        let mut provider = PacketStream::new(Config::default(), handle)
            .expect("Could not create provider")
            .fuse();
        while let Some(packets) = provider.next().await {
    
        }
        handle.interrupt();
    })
}

Dependencies

~8–19MB
~261K SLoC