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 more