Skip to main content

IcmpBuilder

Struct IcmpBuilder 

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

Builder for ICMP packets.

Due to ICMP’s type-specific fields, this builder provides factory methods for common ICMP message types rather than a generic constructor.

Implementations§

Source§

impl IcmpBuilder

Source

pub fn new() -> Self

Create a new ICMP builder with default values (echo request).

Source

pub fn echo_request(id: u16, seq: u16) -> Self

Create an echo request (ping) packet.

§Arguments
  • id - Identifier
  • seq - Sequence number
Source

pub fn echo_reply(id: u16, seq: u16) -> Self

Create an echo reply (pong) packet.

§Arguments
  • id - Identifier (should match request)
  • seq - Sequence number (should match request)
Source

pub fn dest_unreach(code: u8) -> Self

Create a destination unreachable message.

§Arguments
  • code - Specific unreachable code (0-15)
    • 0: Network unreachable
    • 1: Host unreachable
    • 2: Protocol unreachable
    • 3: Port unreachable
    • 4: Fragmentation needed (use dest_unreach_need_frag for this)
Source

pub fn dest_unreach_need_frag(mtu: u16) -> Self

Create a destination unreachable - fragmentation needed message.

§Arguments
  • mtu - Next-hop MTU value
Source

pub fn redirect(code: u8, gateway: Ipv4Addr) -> Self

Create a redirect message.

§Arguments
  • code - Redirect code (0-3)
    • 0: Redirect for network
    • 1: Redirect for host
    • 2: Redirect for TOS and network
    • 3: Redirect for TOS and host
  • gateway - Gateway IP address to redirect to
Source

pub fn time_exceeded(code: u8) -> Self

Create a time exceeded message.

§Arguments
  • code - Time exceeded code
    • 0: TTL exceeded in transit
    • 1: Fragment reassembly time exceeded
Source

pub fn param_problem(ptr: u8) -> Self

Create a parameter problem message.

§Arguments
  • ptr - Pointer to the problematic byte in the original packet
Source

pub fn source_quench() -> Self

Create a source quench message (deprecated).

Source

pub fn timestamp_request( id: u16, seq: u16, ts_ori: u32, ts_rx: u32, ts_tx: u32, ) -> Self

Create a timestamp request message.

§Arguments
  • id - Identifier
  • seq - Sequence number
  • ts_ori - Originate timestamp (milliseconds since midnight UT)
  • ts_rx - Receive timestamp (0 for request)
  • ts_tx - Transmit timestamp (0 for request)
Source

pub fn timestamp_reply( id: u16, seq: u16, ts_ori: u32, ts_rx: u32, ts_tx: u32, ) -> Self

Create a timestamp reply message.

§Arguments
  • id - Identifier (should match request)
  • seq - Sequence number (should match request)
  • ts_ori - Originate timestamp from request
  • ts_rx - Receive timestamp (when request was received)
  • ts_tx - Transmit timestamp (when reply is sent)
Source

pub fn address_mask_request(id: u16, seq: u16) -> Self

Create an address mask request message.

§Arguments
  • id - Identifier
  • seq - Sequence number
Source

pub fn address_mask_reply(id: u16, seq: u16, mask: Ipv4Addr) -> Self

Create an address mask reply message.

§Arguments
  • id - Identifier (should match request)
  • seq - Sequence number (should match request)
  • mask - Address mask
Source

pub fn icmp_type(self, t: u8) -> Self

Set the ICMP type manually (use factory methods instead when possible).

Source

pub fn code(self, c: u8) -> Self

Set the ICMP code manually.

Source

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

Set the checksum manually.

If not set, the checksum will be calculated automatically.

Source

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

Alias for checksum (Scapy compatibility).

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 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 + optional timestamp + payload).

Source

pub fn header_size(&self) -> usize

Get the header size (8 bytes for most, 20 for timestamp).

Source

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

Build the ICMP packet into a new buffer.

Source

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

Build the ICMP packet into an existing buffer.

Source

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

Build just the ICMP header (without payload).

Trait Implementations§

Source§

impl Clone for IcmpBuilder

Source§

fn clone(&self) -> IcmpBuilder

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 IcmpBuilder

Source§

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

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

impl Default for IcmpBuilder

Source§

fn default() -> Self

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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