rust-pcap / pcap

Rust language pcap library
Apache License 2.0
617 stars 142 forks source link

Allow using capture asynchronously, without having to create an allocating StreamCodec. #322

Open Frostie314159 opened 8 months ago

Frostie314159 commented 8 months ago

It would be nice, to be able to use a capture asynchronously, without the Codec forcing you to allocate.

Wojtek242 commented 8 months ago

Could you please give a code sample that you would like to see working with pcap? That way it will be easier to target exactly the feature you would like.

Frostie314159 commented 8 months ago

In my case, I was relying on the fact, that pcap internally just keeps an fd and using tokio, you can do async read and write operations on that. Providing an API similar to that would be great to have. I just have a fixed length array, into which I read the data, process it and then continue to the next packet.

let mut buf = [0x00; 1500];
let len = capture.read(&mut buf).await.unwrap();
Stargateur commented 7 months ago

see https://github.com/rust-pcap/pcap/blob/main/examples/lendingiterprint.rs for no allocating codec

Frostie314159 commented 7 months ago

There is no codec used in that example and it is sync not async.