pub struct Ipv4Builder { /* private fields */ }Expand description
Builder for IPv4 packets.
§Example
use stackforge_core::layer::ipv4::{Ipv4Builder, protocol};
use std::net::Ipv4Addr;
let packet = Ipv4Builder::new()
.src(Ipv4Addr::new(192, 168, 1, 1))
.dst(Ipv4Addr::new(192, 168, 1, 2))
.ttl(64)
.protocol(protocol::TCP)
.dont_fragment()
.build();
assert_eq!(packet.len(), 20); // Minimum header, no payloadImplementations§
Source§impl Ipv4Builder
impl Ipv4Builder
Sourcepub fn from_bytes(data: &[u8]) -> Result<Self, FieldError>
pub fn from_bytes(data: &[u8]) -> Result<Self, FieldError>
Create a builder initialized from an existing packet.
Sourcepub fn ihl(self, ihl: u8) -> Self
pub fn ihl(self, ihl: u8) -> Self
Set the Internet Header Length (in 32-bit words). If not set, will be calculated automatically.
Sourcepub fn total_len(self, len: u16) -> Self
pub fn total_len(self, len: u16) -> Self
Set the total length field. If not set, will be calculated automatically.
Sourcepub fn dont_fragment(self) -> Self
pub fn dont_fragment(self) -> Self
Set the Don’t Fragment flag.
Sourcepub fn allow_fragment(self) -> Self
pub fn allow_fragment(self) -> Self
Clear the Don’t Fragment flag.
Sourcepub fn more_fragments(self) -> Self
pub fn more_fragments(self) -> Self
Set the More Fragments flag.
Sourcepub fn frag_offset(self, offset: u16) -> Self
pub fn frag_offset(self, offset: u16) -> Self
Set the fragment offset (in 8-byte units).
Sourcepub fn frag_offset_bytes(self, offset: u32) -> Self
pub fn frag_offset_bytes(self, offset: u32) -> Self
Set the fragment offset in bytes (will be divided by 8).
Sourcepub fn checksum(self, checksum: u16) -> Self
pub fn checksum(self, checksum: u16) -> Self
Set the checksum manually. If not set, will be calculated automatically.
Sourcepub fn options(self, options: Ipv4Options) -> Self
pub fn options(self, options: Ipv4Options) -> Self
Set the options.
Sourcepub fn option(self, option: Ipv4Option) -> Self
pub fn option(self, option: Ipv4Option) -> Self
Add a single option.
Sourcepub fn with_options<F>(self, f: F) -> Self
pub fn with_options<F>(self, f: F) -> Self
Add options using a builder function.
Sourcepub fn record_route(self, slots: usize) -> Self
pub fn record_route(self, slots: usize) -> Self
Add a Record Route option.
Sourcepub fn router_alert(self, value: u16) -> Self
pub fn router_alert(self, value: u16) -> Self
Add a Router Alert option.
Sourcepub fn append_payload(self, data: &[u8]) -> Self
pub fn append_payload(self, data: &[u8]) -> Self
Append data to the payload.
Sourcepub fn auto_checksum(self, enabled: bool) -> Self
pub fn auto_checksum(self, enabled: bool) -> Self
Enable or disable automatic checksum calculation.
Sourcepub fn auto_length(self, enabled: bool) -> Self
pub fn auto_length(self, enabled: bool) -> Self
Enable or disable automatic length calculation.
Sourcepub fn header_size(&self) -> usize
pub fn header_size(&self) -> usize
Calculate the header size (including options).
Sourcepub fn packet_size(&self) -> usize
pub fn packet_size(&self) -> usize
Calculate the total packet size.
Sourcepub fn build_into(&self, buf: &mut [u8]) -> Result<usize, FieldError>
pub fn build_into(&self, buf: &mut [u8]) -> Result<usize, FieldError>
Build the IPv4 packet into an existing buffer.
Sourcepub fn build_header(&self) -> Vec<u8> ⓘ
pub fn build_header(&self) -> Vec<u8> ⓘ
Build only the header (no payload).
Source§impl Ipv4Builder
impl Ipv4Builder
Source§impl Ipv4Builder
impl Ipv4Builder
Trait Implementations§
Source§impl Clone for Ipv4Builder
impl Clone for Ipv4Builder
Source§fn clone(&self) -> Ipv4Builder
fn clone(&self) -> Ipv4Builder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Ipv4Builder
impl Debug for Ipv4Builder
Source§impl Default for Ipv4Builder
impl Default for Ipv4Builder
Source§impl From<Ipv4Builder> for LayerStack
impl From<Ipv4Builder> for LayerStack
Source§fn from(builder: Ipv4Builder) -> Self
fn from(builder: Ipv4Builder) -> Self
Source§impl IntoLayerStackEntry for Ipv4Builder
impl IntoLayerStackEntry for Ipv4Builder
fn into_layer_stack_entry(self) -> LayerStackEntry
Auto Trait Implementations§
impl Freeze for Ipv4Builder
impl RefUnwindSafe for Ipv4Builder
impl Send for Ipv4Builder
impl Sync for Ipv4Builder
impl Unpin for Ipv4Builder
impl UnsafeUnpin for Ipv4Builder
impl UnwindSafe for Ipv4Builder
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