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
impl IcmpBuilder
Sourcepub fn echo_request(id: u16, seq: u16) -> Self
pub fn echo_request(id: u16, seq: u16) -> Self
Sourcepub fn echo_reply(id: u16, seq: u16) -> Self
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)
Sourcepub fn dest_unreach(code: u8) -> Self
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_fragfor this)
Sourcepub fn dest_unreach_need_frag(mtu: u16) -> Self
pub fn dest_unreach_need_frag(mtu: u16) -> Self
Create a destination unreachable - fragmentation needed message.
§Arguments
mtu- Next-hop MTU value
Sourcepub fn redirect(code: u8, gateway: Ipv4Addr) -> Self
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
Sourcepub fn time_exceeded(code: u8) -> Self
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
Sourcepub fn param_problem(ptr: u8) -> Self
pub fn param_problem(ptr: u8) -> Self
Create a parameter problem message.
§Arguments
ptr- Pointer to the problematic byte in the original packet
Sourcepub fn source_quench() -> Self
pub fn source_quench() -> Self
Create a source quench message (deprecated).
Sourcepub fn timestamp_request(
id: u16,
seq: u16,
ts_ori: u32,
ts_rx: u32,
ts_tx: u32,
) -> Self
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- Identifierseq- Sequence numberts_ori- Originate timestamp (milliseconds since midnight UT)ts_rx- Receive timestamp (0 for request)ts_tx- Transmit timestamp (0 for request)
Sourcepub fn timestamp_reply(
id: u16,
seq: u16,
ts_ori: u32,
ts_rx: u32,
ts_tx: u32,
) -> Self
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 requestts_rx- Receive timestamp (when request was received)ts_tx- Transmit timestamp (when reply is sent)
Sourcepub fn address_mask_request(id: u16, seq: u16) -> Self
pub fn address_mask_request(id: u16, seq: u16) -> Self
Sourcepub fn address_mask_reply(id: u16, seq: u16, mask: Ipv4Addr) -> Self
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
Sourcepub fn icmp_type(self, t: u8) -> Self
pub fn icmp_type(self, t: u8) -> Self
Set the ICMP type manually (use factory methods instead when possible).
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.
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 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 + optional timestamp + payload).
Sourcepub fn header_size(&self) -> usize
pub fn header_size(&self) -> usize
Get the header size (8 bytes for most, 20 for timestamp).
Sourcepub fn build_into(&self, buf: &mut [u8]) -> Result<usize, FieldError>
pub fn build_into(&self, buf: &mut [u8]) -> Result<usize, FieldError>
Build the ICMP packet into an existing buffer.
Sourcepub fn build_header(&self) -> Vec<u8> ⓘ
pub fn build_header(&self) -> Vec<u8> ⓘ
Build just the ICMP header (without payload).
Trait Implementations§
Source§impl Clone for IcmpBuilder
impl Clone for IcmpBuilder
Source§fn clone(&self) -> IcmpBuilder
fn clone(&self) -> IcmpBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more