pub struct L2tpBuilder { /* private fields */ }Expand description
Builder for L2TPv2 packets.
The builder encodes the header flags and optional fields according to RFC 2661. Fields:
- T bit (message type): cleared for data, set for control
- L bit: when set a 2-byte Length field appears after the flags word
- S bit: when set Ns and Nr (2 bytes each) appear after Session ID
- O bit: when set Offset Size + Offset Pad appear after Nr (or Session ID)
- Ver nibble: always 2 for
L2TPv2
Implementations§
Source§impl L2tpBuilder
impl L2tpBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new L2TP data message builder with minimal defaults.
Produces a 6-byte header: \x00\x02\x00\x00\x00\x00 (ver=2, tid=0, sid=0).
Sourcepub fn with_length(self) -> Self
pub fn with_length(self) -> Self
Set the L (length) bit so a Length field will be included in the header.
Sourcepub fn with_sequence(self) -> Self
pub fn with_sequence(self) -> Self
Set the S (sequence) bit so Ns and Nr will be included.
Sourcepub fn with_offset(self) -> Self
pub fn with_offset(self) -> Self
Set the O (offset) bit so Offset Size + Offset Pad will be included.
Sourcepub fn session_id(self, id: u16) -> Self
pub fn session_id(self, id: u16) -> Self
Set the Session ID.
Sourcepub fn ns(self, ns: u16) -> Self
pub fn ns(self, ns: u16) -> Self
Set the Ns (send sequence number) field. Automatically enables the S bit.
Sourcepub fn nr(self, nr: u16) -> Self
pub fn nr(self, nr: u16) -> Self
Set the Nr (receive sequence number) field. Automatically enables the S bit.
Sourcepub fn offset_size(self, size: u16) -> Self
pub fn offset_size(self, size: u16) -> Self
Set the Offset Size field. Automatically enables the O bit.
Sourcepub fn payload<T: Into<Vec<u8>>>(self, data: T) -> Self
pub fn payload<T: Into<Vec<u8>>>(self, data: T) -> Self
Set the payload (data after the L2TP header).
Sourcepub fn control_length() -> Self
pub fn control_length() -> Self
Create a control message with the Length bit set (matching Scapy’s
L2TP(hdr="control+length") default).
Sourcepub fn header_size(&self) -> usize
pub fn header_size(&self) -> usize
Compute the header length in bytes.
Sourcepub fn packet_size(&self) -> usize
pub fn packet_size(&self) -> usize
Compute the total packet size (header + payload).
Sourcepub fn build_into(&self, buf: &mut Vec<u8>)
pub fn build_into(&self, buf: &mut Vec<u8>)
Serialize into an existing buffer (must be at least packet_size() bytes).
Trait Implementations§
Source§impl Clone for L2tpBuilder
impl Clone for L2tpBuilder
Source§fn clone(&self) -> L2tpBuilder
fn clone(&self) -> L2tpBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more