Rscap is a multi-purpose library for network packet capture/transmission and packet building. Its aims are twofold:
libpcap
, but written from the ground up in Rust)scapy
, but with strong typing and significantly improved performance)The pkts
submodule focuses solely on (2)--it provides a packet-building API for a wide variety of network protocol layers.
This library isn't meant to only cover Physical through Transport layers or stateless protocols--thanks to Sequence
and Session
types (which defragment/reorder packets and track packet state, respectively), any application-layer protocol can be easily captured and decoded.
scapy
may find the API surprisingly familiar, especially for layer composition and indexing operations:```rust use layers::{ip::Ipv4, tcp::Tcp};
let pkt = Ip::new() / Tcp::new(); pkt[Tcp].setsport(80); pkt[Tcp].setdport(12345); ```
Sequence
types that transparently handle defragmentation and reordering. Sequence
types can even be stacked so that application-layer data can easily be reassembled from captured packets. They even work in no-std
environments with or without alloc
.Session
types that handle these kinds of packets--Sessions ensure that packets are validated based on the current expected state of the protocol. Just like Sequence
, Session
types are compatible with no-std
environments and do not require alloc
.The source code of this project is made available under the GNU General Public License, version 2.
Requests regarding other licensing options can be made to email address here.