MCPcopy Index your code
hub / github.com/JulianSchmid/etherparse

github.com/JulianSchmid/etherparse @v0.20.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.20.3 ↗ · + Follow
2,177 symbols 5,051 edges 260 files 431 documented · 20%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Crates.io docs.rs Build Status Github Build Status Gitlab

etherparse

A zero allocation supporting library for parsing & writing a bunch of packet based protocols (EthernetII, IPv4, IPv6, UDP, TCP ...).

Currently supported are: * Ethernet II * IEEE 802.1Q VLAN Tagging Header * MACsec (IEEE 802.1AE) * ARP * IPv4 * IPv6 (supporting the most common extension headers, but not all) * UDP * TCP * ICMP & ICMPv6 (not all message types are supported)

Reconstruction of fragmented IP packets is also supported, but requires allocations.

Usage

Add the following to your Cargo.toml:

[dependencies]
etherparse = "0.20.3"

What is etherparse?

Etherparse is intended to provide the basic network parsing functions that allow for easy analysis, transformation or generation of recorded network data.

Some key points are:

  • It is completely written in Rust and thoroughly tested.
  • Special attention has been paid to not use allocations or syscalls except in the "defragmentation" code.
  • The package is still in development and can & will still change.
  • The current focus of development is on the most popular protocols in the internet & transport layer.

How to parse network packages?

Etherparse gives you two options for parsing network packages automatically:

Slicing the packet

Here the different components in a packet are separated without parsing all their fields. For each header a slice is generated that allows access to the fields of a header.

match SlicedPacket::from_ethernet(&packet) {
    Err(value) => println!("Err {:?}", value),
    Ok(value) => {
        println!("link: {:?}", value.link);
        println!("link_exts: {:?}", value.link_exts); // contains vlan & macsec
        println!("net: {:?}", value.net); // contains ip & arp
        println!("transport: {:?}", value.transport);
    }
};

This is the faster option if your code is not interested in all fields of all the headers. It is a good choice if you just want filter or find packets based on a subset of the headers and/or their fields.

Depending from which point downward you want to slice a package check out the functions:

In case you want to parse cut off packets (e.g. packets returned in in ICMP message) you can use the "lax" parsing methods:

Deserializing all headers into structs

This option deserializes all known headers and transfers their contents to header structs.

match PacketHeaders::from_ethernet_slice(&packet) {
    Err(value) => println!("Err {:?}", value),
    Ok(value) => {
        println!("link: {:?}", value.link);
        println!("link_exts: {:?}", value.link_exts); // contains vlan & macsec
        println!("net: {:?}", value.net); // contains ip & arp
        println!("transport: {:?}", value.transport);
    }
};

This option is slower then slicing when only few fields are accessed. But it can be the faster option or useful if you are interested in most fields anyways or if you want to re-serialize the headers with modified values.

Depending from which point downward you want to unpack a package check out the functions

In case you want to parse cut off packets (e.g. packets returned in in ICMP message) you can use the "lax" parsing methods:

Manually slicing only one packet layer

It is also possible to only slice one packet layer:

The resulting data types allow access to both the header(s) and the payload of the layer and will automatically limit the length of payload if the layer has a length field limiting the payload (e.g. the payload of IPv6 packets will be limited by the "payload length" field in an IPv6 header).

Manually slicing & parsing only headers

It is also possible just to parse headers. Have a look at the documentation for the following [NAME]HeaderSlice.from_slice methods, if you want to just slice the header:

And for deserialization into the corresponding header structs have a look at:

Extension points exported contracts — how you extend this code

CoreWrite (Interface)
Internal writer abstraction used to share serialization code between `std` and `no_std` code paths. [3 implementers]
etherparse/src/writer.rs

Core symbols most depended-on inside this repo

len
called by 339
etherparse/src/net/ipv4_options.rs
header_len
called by 284
etherparse/src/net/ipv6_exts.rs
to_bytes
called by 150
etherparse/src/net/arp_packet.rs
add
called by 133
etherparse/src/defrag/ip_defrag_buf.rs
map_err
called by 130
etherparse/src/net/ip_auth_header.rs
hash
called by 124
etherparse/src/net/arp_packet.rs
as_ref
called by 99
etherparse/src/net/ipv4_options.rs
len
called by 96
etherparse/src/transport/tcp_options.rs

Shape

Method 1,238
Function 698
Class 135
Enum 105
Interface 1

Languages

Rust100%

Modules by API surface

etherparse/src/packet_builder.rs67 symbols
etherparse/src/transport/tcp_options.rs37 symbols
etherparse/src/transport/tcp_slice.rs32 symbols
etherparse/src/transport/tcp_header_slice.rs32 symbols
etherparse/src/net/ipv6_exts.rs30 symbols
etherparse/src/transport/tcp_header.rs28 symbols
etherparse/src/net/ipv4_options.rs28 symbols
etherparse/src/sliced_packet.rs27 symbols
etherparse/src/net/ipv4_header_slice.rs27 symbols
etherparse/src/checksum.rs27 symbols
etherparse/src/lax_sliced_packet.rs26 symbols
etherparse/src/net/ipv4_header.rs25 symbols

For agents

$ claude mcp add etherparse \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact