IpStackUnknownTransport

Struct IpStackUnknownTransport 

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

A stream for unknown transport layer protocols.

This type handles network packets with transport protocols that are not TCP or UDP (e.g., ICMP, IGMP, ESP, etc.). It provides methods to inspect the packet details and send responses.

§Examples

use ipstack::{IpStack, IpStackConfig, IpStackStream};

if let IpStackStream::UnknownTransport(unknown) = ip_stack.accept().await? {
    println!("Unknown transport protocol: {:?}", unknown.ip_protocol());
    println!("Source: {}", unknown.src_addr());
    println!("Destination: {}", unknown.dst_addr());
    println!("Payload: {} bytes", unknown.payload().len());
     
    // Send a response
    unknown.send(vec![0x08, 0x00, 0x00, 0x00])?;
}

Implementations§

Source§

impl IpStackUnknownTransport

Source

pub fn src_addr(&self) -> IpAddr

Returns the source IP address of the packet.

§Examples
let src = unknown.src_addr();
println!("Source: {}", src);
Source

pub fn dst_addr(&self) -> IpAddr

Returns the destination IP address of the packet.

§Examples
let dst = unknown.dst_addr();
println!("Destination: {}", dst);
Source

pub fn payload(&self) -> &[u8]

Returns the payload of the packet.

§Examples
let payload = unknown.payload();
println!("Payload: {} bytes", payload.len());
Source

pub fn ip_protocol(&self) -> IpNumber

Returns the IP protocol number of the packet.

§Examples
let protocol = unknown.ip_protocol();
println!("Protocol: {:?}", protocol);
Source

pub fn send(&self, payload: Vec<u8>) -> Result<()>

Send a response packet.

This method sends one or more packets with the given payload, automatically fragmenting the data if it exceeds the MTU.

§Arguments
  • payload - The payload to send
§Errors

Returns an error if the packet cannot be sent.

§Examples
// Send an ICMP echo reply
unknown.send(vec![0x08, 0x00, 0x00, 0x00])?;
Source

pub fn create_rev_packet(&self, payload: &mut Vec<u8>) -> Result<NetworkPacket>

Create a reverse packet for sending a response.

This method creates a packet with swapped source and destination addresses, suitable for sending responses to received packets. If the payload exceeds the MTU, only a portion of the payload is consumed and included in the packet.

§Arguments
  • payload - A mutable reference to the payload vector. If the payload exceeds the MTU, data is drained from the front. Otherwise, the entire vector is taken.
§Returns

Returns a NetworkPacket with the reversed addresses and up to MTU bytes of payload.

§Errors

Returns an error if the packet cannot be constructed.

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> 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, 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.