rust-pcap / pcap

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

Set timestamp precision on dead capture #243

Closed gmacon closed 2 years ago

gmacon commented 2 years ago

Currently, Capture::dead calls pcap_open_dead, but there should be a way to call pcap_open_dead_with_tstamp_precision instead. I propose adding a new Capture::dead_with_precision function to handle that.

Aside: If I were designing the API from scratch, I might have a separate DeadCaptureBuilder that provides default values for the snaplen and precision and lets you set either or both before finally calling pcap_open_dead_with_tstamp_precision at the end. Would there be any objection to such an API?

Stargateur commented 2 years ago

I'm not sure I totally follow the idea. We didn't hit 1.0.0, while I don't think we should change everything, small or medium change are ok for me.

gmacon commented 2 years ago

Maybe I can help with what I think the usage would look like:

let dead_capture = Capture::dead_with_options(Linktype::ETHERNET)
    .precision(Precision::Nano)
    .snaplen(60)
    .activate()?;

so builder pattern with the link type required and the precision and snaplen optional.