Expand description
§UDP Packet Header Construction
§Purpose
This module provides a utility to construct the headers for a UDP/IPv4/Ethernet packet. This is essential for applications using AF_XDP that need to manually build entire packets before sending them.
§How it works
It uses the etherparse crate’s PacketBuilder to efficiently layer the Ethernet II,
IPv4, and UDP headers. The headers are written directly into a fixed-size [u8; 42]
array to avoid heap allocations. A custom HdrWrite struct, which implements
std::io::Write, acts as a temporary writer to capture the builder’s output.
§Main components
write_udp_header_for(): The primary function that takes source/destination addresses and ports and returns a 42-byte array containing the packet header.HdrWrite: A helper struct implementingio::Writeto enable writing into a fixed-size buffer without extra allocations.
Structs§
- HdrWrite
- A helper struct that implements
std::io::Writefor a fixed-size byte array.
Functions§
- write_
udp_ header_ for - Constructs Ethernet, IPv4, and UDP headers for a packet.