netpkt/pkt.rs#
Source: lib/netpkt/pkt.rs
pkt -- a packet buffer with headroom: headers are prepended in place
Pkt::new(headroom, payload) the payload behind `headroom` free bytes
push(n) -> &mut [u8] n more bytes at the front (the new header to fill in);
grows the headroom when it runs out (a copy, still correct)
pull(n) -> bool drops n bytes at the front (a header that was read)
bytes() / bytes_mut() / len() the packet from the current front
extend(data) / truncate(len) the tail
into_vec() the packet alone
A segment is built once: payload first, then TCP, IP, VLAN and Ethernet headers in front of
it, without moving the payload.
/// room for Ethernet + 802.1Q + IPv4 with options + TCP with options (14 + 4 + 60 + 60)
HEADROOM: usize = 144
struct Pkt
impl Pkt
fn new(headroom: usize, payload: &[u8]) -> Pktpayloadbehindheadroomfree bytesfn empty() -> Pktan empty packet with the standard headroomfn from_vec(v: Vec<u8>) -> Pkta received frame (no headroom)fn len(&self) -> usizefn is_empty(&self) -> boolfn headroom(&self) -> usizefn bytes(&self) -> &[u8]fn bytes_mut(&mut self) -> &mut [u8]fn push(&mut self, n: usize) -> &mut [u8]nnew bytes at the front, zeroed, for the caller to fill infn pull(&mut self, n: usize) -> booldropsnbytes at the front; false (and nothing dropped) when the packet is shorterfn extend(&mut self, data: &[u8])fn truncate(&mut self, len: usize)fn into_vec(mut self) -> Vec<u8>the packet bytes without the headroom