Crates.io | rtshark |
lib.rs | rtshark |
version | 3.0.0 |
source | src |
created_at | 2022-05-18 22:00:56.220625 |
updated_at | 2024-11-16 17:32:41.440201 |
description | A Rust interface for TShark |
homepage | https://github.com/CrabeDeFrance/rtshark |
repository | https://github.com/CrabeDeFrance/rtshark |
max_upload_size | |
id | 589336 |
size | 186,011 |
A Rust interface to TShark, the famous network protocol analyzer. TShark is a part of Wireshark distribution. This crate provides an API to start TShark and analyze it's output. It lets you capture packet data from a live network or read packets from a previously saved capture file, printing a decoded form of those packets. TShark's native capture file format is pcapng format, which is also the format used by Wireshark and various other tools.
TShark application must be installed for this crate to work properly.
This crates supports both offline processing (using pcap file) and live analysis (using an interface or a fifo).
// Creates a builder with needed tshark parameters
let builder = rtshark::RTSharkBuilder::builder()
.input_path("/tmp/my.pcap");
// Start a new tshark process
let mut rtshark = builder.spawn()
.unwrap_or_else(|e| panic!("Error starting tshark: {e}"));
// read packets until the end of the PCAP file
while let Some(packet) = rtshark.read().unwrap_or_else(|e| {
eprintln!("Error parsing tshark output: {e}");
None
}) {
for layer in packet {
println!("Layer: {}", layer.name());
for metadata in layer {
println!("\t{}", metadata.display());
}
}
}
There is actually no specific work to add more TShark parameters. If you miss an important parameter, you can create an issue. But if you want something to be added quickly, please do a patch proposal with the missing parameter or feature (it is easy!). Of course, any new proposal should include documentation to explain how to use it and an unit test to validate it.
This library follows the Semantic Versioning rules https://semver.org/, including :
Many thanks to Emmanuel Touzery for creating Hotwire. Core parts of this crate are coming from this tool.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.