13 stable releases

2.9.0 Sep 15, 2024
2.8.0 Jun 24, 2024
2.7.1 Nov 6, 2023
2.5.0 Jul 24, 2023
1.0.0 May 18, 2022

#231 in Network programming

Download history 63/week @ 2024-06-13 243/week @ 2024-06-20 62/week @ 2024-06-27 123/week @ 2024-07-04 55/week @ 2024-07-11 59/week @ 2024-07-18 106/week @ 2024-07-25 94/week @ 2024-08-01 78/week @ 2024-08-08 87/week @ 2024-08-15 117/week @ 2024-08-22 73/week @ 2024-08-29 208/week @ 2024-09-05 709/week @ 2024-09-12 193/week @ 2024-09-19 117/week @ 2024-09-26

1,236 downloads per month
Used in rpltree

MIT/Apache

105KB
1.5K SLoC

rtshark

Crate Crate Crate Documentation dependency status

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).

Example

// 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());
        }
    }
}

Development rules

New parameters

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.

Version

This library follows the Semantic Versioning rules https://semver.org/, including :

  • Only make breaking changes when you increment the major version. Don't break the build.
  • Don't add any new public API (no new pub anything) in patch-level versions. Always increment the minor version if you add any new pub structs, traits, fields, types, functions, methods or anything else.

Credits

Many thanks to Emmanuel Touzery for creating Hotwire. Core parts of this crate are coming from this tool.

License

Licensed under either of

at your option.

Contribution

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.

Dependencies

~2.5MB
~40K SLoC