pub struct UdpBuilder { /* private fields */ }Expand description
Builder for UDP packets.
Implementations§
Source§impl UdpBuilder
impl UdpBuilder
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 length(self, len: u16) -> Self
pub fn length(self, len: u16) -> Self
Set the UDP length manually.
If not set, the length will be calculated automatically (8 + payload length).
Sourcepub fn checksum(self, csum: u16) -> Self
pub fn checksum(self, csum: u16) -> Self
Set the checksum manually.
If not set, the checksum will be calculated automatically if IP addresses are provided.
Sourcepub fn enable_auto_length(self) -> Self
pub fn enable_auto_length(self) -> Self
Enable automatic length calculation (default).
Sourcepub fn disable_auto_length(self) -> Self
pub fn disable_auto_length(self) -> Self
Disable automatic length calculation.
Sourcepub fn enable_auto_checksum(self) -> Self
pub fn enable_auto_checksum(self) -> Self
Enable automatic checksum calculation (default).
Sourcepub fn disable_auto_checksum(self) -> Self
pub fn disable_auto_checksum(self) -> Self
Disable automatic checksum calculation.
Sourcepub fn src_ipv4(self, addr: Ipv4Addr) -> Self
pub fn src_ipv4(self, addr: Ipv4Addr) -> Self
Set source IPv4 address for checksum calculation.
Sourcepub fn dst_ipv4(self, addr: Ipv4Addr) -> Self
pub fn dst_ipv4(self, addr: Ipv4Addr) -> Self
Set destination IPv4 address for checksum calculation.
Sourcepub fn src_ipv6(self, addr: Ipv6Addr) -> Self
pub fn src_ipv6(self, addr: Ipv6Addr) -> Self
Set source IPv6 address for checksum calculation.
Sourcepub fn dst_ipv6(self, addr: Ipv6Addr) -> Self
pub fn dst_ipv6(self, addr: Ipv6Addr) -> Self
Set destination IPv6 address for checksum calculation.
Sourcepub fn ipv4_addrs(self, src: Ipv4Addr, dst: Ipv4Addr) -> Self
pub fn ipv4_addrs(self, src: Ipv4Addr, dst: Ipv4Addr) -> Self
Set both source and destination IPv4 addresses.
Sourcepub fn ipv6_addrs(self, src: Ipv6Addr, dst: Ipv6Addr) -> Self
pub fn ipv6_addrs(self, src: Ipv6Addr, dst: Ipv6Addr) -> Self
Set both source and destination IPv6 addresses.
Sourcepub fn append_payload<T: AsRef<[u8]>>(self, data: T) -> Self
pub fn append_payload<T: AsRef<[u8]>>(self, data: T) -> Self
Append to the payload data.
Sourcepub fn packet_size(&self) -> usize
pub fn packet_size(&self) -> usize
Get the total packet size (header + payload).
Sourcepub fn header_size(&self) -> usize
pub fn header_size(&self) -> usize
Get the header size (always 8 bytes for UDP).
Sourcepub fn build_into(&self, buf: &mut [u8]) -> Result<usize, FieldError>
pub fn build_into(&self, buf: &mut [u8]) -> Result<usize, FieldError>
Build the UDP packet into an existing buffer.
Sourcepub fn build_header(&self) -> Vec<u8> ⓘ
pub fn build_header(&self) -> Vec<u8> ⓘ
Build just the UDP header (without payload).
Source§impl UdpBuilder
impl UdpBuilder
Sourcepub fn dhcp_client() -> Self
pub fn dhcp_client() -> Self
Create a DHCP client packet builder (ports 68 -> 67).
Sourcepub fn dhcp_server() -> Self
pub fn dhcp_server() -> Self
Create a DHCP server packet builder (ports 67 -> 68).
Trait Implementations§
Source§impl Clone for UdpBuilder
impl Clone for UdpBuilder
Source§fn clone(&self) -> UdpBuilder
fn clone(&self) -> UdpBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for UdpBuilder
impl Debug for UdpBuilder
Source§impl Default for UdpBuilder
impl Default for UdpBuilder
Source§impl From<UdpBuilder> for LayerStack
impl From<UdpBuilder> for LayerStack
Source§fn from(builder: UdpBuilder) -> Self
fn from(builder: UdpBuilder) -> Self
Source§impl IntoLayerStackEntry for UdpBuilder
impl IntoLayerStackEntry for UdpBuilder
fn into_layer_stack_entry(self) -> LayerStackEntry
Auto Trait Implementations§
impl Freeze for UdpBuilder
impl RefUnwindSafe for UdpBuilder
impl Send for UdpBuilder
impl Sync for UdpBuilder
impl Unpin for UdpBuilder
impl UnsafeUnpin for UdpBuilder
impl UnwindSafe for UdpBuilder
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