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
impl IpStackUnknownTransport
Sourcepub fn src_addr(&self) -> IpAddr
pub fn src_addr(&self) -> IpAddr
Returns the source IP address of the packet.
§Examples
let src = unknown.src_addr();
println!("Source: {}", src);Sourcepub fn dst_addr(&self) -> IpAddr
pub fn dst_addr(&self) -> IpAddr
Returns the destination IP address of the packet.
§Examples
let dst = unknown.dst_addr();
println!("Destination: {}", dst);Sourcepub fn payload(&self) -> &[u8] ⓘ
pub fn payload(&self) -> &[u8] ⓘ
Returns the payload of the packet.
§Examples
let payload = unknown.payload();
println!("Payload: {} bytes", payload.len());Sourcepub fn ip_protocol(&self) -> IpNumber
pub fn ip_protocol(&self) -> IpNumber
Returns the IP protocol number of the packet.
§Examples
let protocol = unknown.ip_protocol();
println!("Protocol: {:?}", protocol);Sourcepub fn send(&self, payload: Vec<u8>) -> Result<()>
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])?;Sourcepub fn create_rev_packet(&self, payload: &mut Vec<u8>) -> Result<NetworkPacket>
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.