Crates.io | libpcapng-rs |
lib.rs | libpcapng-rs |
version | 0.1.4 |
source | src |
created_at | 2024-02-28 06:14:55.085095 |
updated_at | 2024-02-28 16:23:25.224942 |
description | Rust wrapper for libpcapng library |
homepage | |
repository | https://github.com/jumpespllc/libpcapng-rs |
max_upload_size | |
id | 1156138 |
size | 17,697 |
libpcapng-rs
provides a Rust interface to libpcapng.
The main features provided at the moment are:
Add this to your Cargo.toml
:
[dependencies]
libpcapng_rs = { version = "0.1", features = ["static"] }
This crate will compile libpcapng from sources and link it statically to your executable. To compile libpcapng you'll need:
make
wandio
pybind11
cmake
brew install wandio cmake pybind11
sudo apt-get install build-essential cmake libwandio1 libwandio1-dev pybind11-dev python3-pybind11
# ...
[dependencies]
libpcapng-rs = { version="0.1.3", features = ["static"] }
use libpcapng_rs::{PcapNg, PcapNgOpenMode};
use std::fs;
fn main() {
let mut pcap_writer = PcapNg::new("test.pcapng", PcapNgOpenMode::Write);
pcap_writer.open().expect("issue opening file");
pcap_writer.write_custom("this is a test".as_bytes().to_vec()).expect("issue writing custom frame");
pcap_writer.close();
let mut pcap_writer = PcapNg::new("test.pcapng", PcapNgOpenMode::Read);
pcap_writer.open().expect("issue opening file");
pcap_writer.read_packets(Some(callback_rs)).unwrap();
pcap_writer.close();
fs::remove_file("test.pcapng").unwrap();
}
fn callback_rs(block_counter: u32, block_type: u32, block_total_length: u32, bytes: Vec<u8>) {
println!("hello world");
println!("block_counter: {}, block_type: {}, block_total_length: {} bytes {:02X?}", block_counter, block_type, block_total_length, bytes);
}
hello world
block_counter: 1, block_type: 168627466, block_total_length: 28 bytes [4D, 3C, 2B, 1A, 01, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 1C, 00, 00, 00]
hello world
block_counter: 2, block_type: 1, block_total_length: 20 bytes [65, 00, 00, 00, 00, 00, 00, 00, 14, 00, 00, 00]
hello world
block_counter: 3, block_type: 2989, block_total_length: 32 bytes [69, 7A, 00, 00, 74, 68, 69, 73, 20, 69, 73, 20, 61, 20, 74, 65, 73, 74, 00, 00, 20, 00, 00, 00]