Skip to main content

UdpBuilder

Struct UdpBuilder 

Source
pub struct UdpBuilder { /* private fields */ }
Expand description

Builder for UDP packets.

Implementations§

Source§

impl UdpBuilder

Source

pub fn new() -> Self

Create a new UDP builder with default values.

Source

pub fn from_bytes(data: &[u8]) -> Result<Self, FieldError>

Create a builder initialized from an existing packet.

Source

pub fn src_port(self, port: u16) -> Self

Set the source port.

Source

pub fn sport(self, port: u16) -> Self

Alias for src_port (Scapy compatibility).

Source

pub fn dst_port(self, port: u16) -> Self

Set the destination port.

Source

pub fn dport(self, port: u16) -> Self

Alias for dst_port (Scapy compatibility).

Source

pub fn length(self, len: u16) -> Self

Set the UDP length manually.

If not set, the length will be calculated automatically (8 + payload length).

Source

pub fn len(self, len: u16) -> Self

Alias for length (Scapy compatibility).

Source

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.

Source

pub fn chksum(self, csum: u16) -> Self

Alias for checksum (Scapy compatibility).

Source

pub fn enable_auto_length(self) -> Self

Enable automatic length calculation (default).

Source

pub fn disable_auto_length(self) -> Self

Disable automatic length calculation.

Source

pub fn enable_auto_checksum(self) -> Self

Enable automatic checksum calculation (default).

Source

pub fn disable_auto_checksum(self) -> Self

Disable automatic checksum calculation.

Source

pub fn src_ipv4(self, addr: Ipv4Addr) -> Self

Set source IPv4 address for checksum calculation.

Source

pub fn dst_ipv4(self, addr: Ipv4Addr) -> Self

Set destination IPv4 address for checksum calculation.

Source

pub fn src_ipv6(self, addr: Ipv6Addr) -> Self

Set source IPv6 address for checksum calculation.

Source

pub fn dst_ipv6(self, addr: Ipv6Addr) -> Self

Set destination IPv6 address for checksum calculation.

Source

pub fn ipv4_addrs(self, src: Ipv4Addr, dst: Ipv4Addr) -> Self

Set both source and destination IPv4 addresses.

Source

pub fn ipv6_addrs(self, src: Ipv6Addr, dst: Ipv6Addr) -> Self

Set both source and destination IPv6 addresses.

Source

pub fn payload<T: Into<Vec<u8>>>(self, data: T) -> Self

Set the payload data.

Source

pub fn append_payload<T: AsRef<[u8]>>(self, data: T) -> Self

Append to the payload data.

Source

pub fn packet_size(&self) -> usize

Get the total packet size (header + payload).

Source

pub fn header_size(&self) -> usize

Get the header size (always 8 bytes for UDP).

Source

pub fn build(&self) -> Vec<u8>

Build the UDP packet into a new buffer.

Source

pub fn build_into(&self, buf: &mut [u8]) -> Result<usize, FieldError>

Build the UDP packet into an existing buffer.

Source

pub fn build_header(&self) -> Vec<u8>

Build just the UDP header (without payload).

Source§

impl UdpBuilder

Source

pub fn dns_query() -> Self

Create a DNS query packet builder (port 53).

Source

pub fn dhcp_client() -> Self

Create a DHCP client packet builder (ports 68 -> 67).

Source

pub fn dhcp_server() -> Self

Create a DHCP server packet builder (ports 67 -> 68).

Source

pub fn ntp() -> Self

Create a NTP packet builder (port 123).

Trait Implementations§

Source§

impl Clone for UdpBuilder

Source§

fn clone(&self) -> UdpBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UdpBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for UdpBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<UdpBuilder> for LayerStack

Source§

fn from(builder: UdpBuilder) -> Self

Converts to this type from the input type.
Source§

impl IntoLayerStackEntry for UdpBuilder

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V