5 releases

0.1.4 Nov 27, 2020
0.1.3 May 24, 2020
0.1.2 Jul 29, 2017
0.1.1 Jun 9, 2017
0.1.0 Jun 9, 2017

#1106 in Network programming

Download history 127/week @ 2024-01-02 417/week @ 2024-01-09 428/week @ 2024-01-16 596/week @ 2024-01-23 299/week @ 2024-01-30 217/week @ 2024-02-06 269/week @ 2024-02-13 574/week @ 2024-02-20 575/week @ 2024-02-27 621/week @ 2024-03-05 544/week @ 2024-03-12 615/week @ 2024-03-19 544/week @ 2024-03-26 449/week @ 2024-04-02 526/week @ 2024-04-09 421/week @ 2024-04-16

2,053 downloads per month
Used in 7 crates

WTFPL license


packet Crates.io packet WTFPL Build Status

This crate allows the parsing and creation of various network packets with an ergonomic API.


First, add the following to your Cargo.toml:

packet = "0.1"

Next, add this to your crate root:

extern crate packet;


Packets take any type implementing AsRef<[u8]>, this means they can borrow an &[u8] or own a Vec<u8> or your own buffer type without needing different types or annoying lifetime parameters.

If the type also implements AsMut<[u8]> some fields are modifiable in place instead of going through a builder, not all fields are settable this way, for instance any fields that have a dynamic size.

Fields in any packet are parsed lazily directly from the buffer, the only exception are fields that are required to verify the packet is correct.

The correctness check doesn't do any checksum validation, this is because some protocols require additional information to calculate the checksum, for instance TCP and UDP require the IP packet to validate.


Buffers are abstractions over growable or static slices, they implement a layered setup where each builder creates its own layer and any accesses to the buffer start from where the layer starts.

The buffer can be grown, but the operation may fail if the underlying buffer is not growable, static buffers will only fail if they can't accomodate the requested size.


Builders are structures that take a Buffer (or create one internally) and incrementally define a new packet.

Builders of upper layer protocols usually provide a way to create a specific sub-protocol, for example ip::v4::Builder allows creating an udp::Builder or tcp::Builder and deal with checksuming and length delimiting as needed.


Creating an ICMP packet echo request packet.

extern crate packet;
use packet::builder::Builder;
use packet::icmp;

fn main() {
	let packet = icmp::Builder::default()


~26K SLoC