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 moreSource§impl Debug for L2tpBuilder
impl Debug for L2tpBuilder
Source§impl Default for L2tpBuilder
impl Default for L2tpBuilder
Source§fn default() -> L2tpBuilder
fn default() -> L2tpBuilder
Source§impl IntoLayerStackEntry for L2tpBuilder
impl IntoLayerStackEntry for L2tpBuilder
fn into_layer_stack_entry(self) -> LayerStackEntry
Auto Trait Implementations§
impl Freeze for L2tpBuilder
impl RefUnwindSafe for L2tpBuilder
impl Send for L2tpBuilder
impl Sync for L2tpBuilder
impl Unpin for L2tpBuilder
impl UnsafeUnpin for L2tpBuilder
impl UnwindSafe for L2tpBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more