Rscap
rscap - Rust packet capture and manipulation utilities
rscap is a multi-purpose library for network packet capture/transmission and packet building. Its aims are twofold:
- To provide Rust-native platform tools for packet capture and transmission (comparable to
libpcap, but written from the ground up in Rust) - To expose a robust and ergonomic API for building packets and accessing/modifying packet data fields in various network protocols (like
scapy, but with strong typing and significantly improved performance)
The rscap submodule focuses specifically on (1)--it provides safe, Rust-native APIs for capturing packets over network interfaces. Linux is currently the only supported operating system, though multi-platform API support for MacOS, BSD and Windows is in the pipeline.
Features
- Platform-independent interface for packet capture/transmission:
rscapaims to provide a single unified interface for capturing and transmitting packets across any supported platform. Additionally, the library exposes safe abstractions of platform-specific packet capture tools (such asAF_PACKET/PACKET_MMAPsockets in Linux) to support cases where fine-grained control or platform-specific features are desired. - Robust APIs for building/modifying packets: the
pktssubmodule provides simple operations to combine various layers into a single packet, and to index into a different layers of a packet to retrieve or modify fields. Users ofscapymay find the API surprisingly familiar, especially for layer composition and indexing operations:
use ;
let pkt = new / new;
pkt.set_sport;
pkt.set_dport;
- Packet defragmentation/reordering: In some protocols, packets may be fragmented (such as IPv4) or arrive out-of-order (TCP, SCTP, etc.).
rscapovercomes both of these issues throughSequencetypes that transparently handle defragmentation and reordering.Sequencetypes can even be stacked so that application-layer data can easily be reassembled from captured packets. They even work inno-stdenvironments with or withoutalloc. - Stateful packet support: Many network protocols are stateful, and interpreting packets from such protocols can be difficult (if not impossible) to accomplish unless information about the protocol session is stored.
rscapprovidesSessiontypes that handle these kinds of packets--Sessions ensure that packets are validated based on the current expected state of the protocol. Just likeSequence,Sessiontypes are compatible withno-stdenvironments and do not requirealloc.
License
The source code of this project is licensed under either the MIT License or the Apache 2.0 License, at your option.