rusticata / pcap-parser

PCAP/PCAPNG file format parser written in pure Rust. Fast, zero-copy, safe.
Other
104 stars 24 forks source link

could not find `data` in `pcap_parser` #17

Closed allengrant closed 2 years ago

allengrant commented 2 years ago

Has there been a recent change to the pcap-parser API? I ran a minimal example and go the following import error.

   Compiling test-rust v0.1.0 (/Users/w/Dropbox/Codin/test-rust)
error[E0432]: unresolved import `pcap_parser::data`
 --> src/main.rs:1:18
  |
1 | use pcap_parser::data::{get_packetdata, PacketData};
  |                  ^^^^ could not find `data` in `pcap_parser`

To prove I'm not insane, I build a minimal project as follows:

Cargo.toml:

[package]
name = "test-rust"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
pcap-parser = "0.13.1"

main.rs:

use pcap_parser::data::{get_packetdata, PacketData};
use pcap_parser::pcapng::EnhancedPacketBlock;
use pcap_parser::Linktype;

fn parse_block_content<'a>(
    epb: &'a EnhancedPacketBlock<'_>,
    linktype: Linktype
) -> Option<()> {
    let packet_data =  get_packetdata(epb.data, linktype, epb.caplen as usize)?;
    match packet_data {
        PacketData::L3(_, _data) => {
            // ...
        },
        _ => println!("Unsupported link type"),
    }
    Some(())
}

fn main() {

}

The latter file is taken exactly from the docs.

chifflier commented 2 years ago

You need to enable the data feature to use this module. Change your Cargo.toml to look like:

pcap-parser = { version="0.13.1", features=["data"] }
chifflier commented 2 years ago

Additional note: this should be visible in the docs, I think some instructions are missing so rustdoc shows the required features. I'll look into this

chifflier commented 2 years ago

After upload of new version 0.13.2, the data module documentation mentions This is supported on crate feature data only. Closing this issue, thanks!