Skip to main content

AsyncPacketSocket

Struct AsyncPacketSocket 

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

An asynchronous socket wrapper for sending and receiving network packets.

This struct provides an async interface for working with raw sockets using the Tokio runtime.

Implementations§

Source§

impl AsyncPacketSocket

Source

pub async fn new(protocol: Protocol) -> Result<Self>

Creates a new async raw socket for the specified protocol.

§Arguments
  • protocol - The protocol to use (e.g., TCP, UDP)
Source

pub async fn bind(&self, addr: Ipv4Addr) -> Result<()>

Binds the socket to a specific network interface.

§Arguments
  • addr - The IPv4 address to bind to
Source

pub async fn send<P: PacketBuilder>( &self, packet: &P, dst_addr: Ipv4Addr, ) -> Result<usize, PacketError>

Sends a packet asynchronously to the specified destination.

§Arguments
  • packet - The packet to send
  • dst_addr - The destination IPv4 address
§Returns
  • Ok(usize) - The number of bytes sent
  • Err(PacketError) - If sending fails
Source

pub async fn receive( &self, buffer: &mut [u8], ) -> Result<(usize, Ipv4Addr), PacketError>

Receives a packet asynchronously into the provided buffer.

§Arguments
  • buffer - The buffer to store the received packet
§Returns
  • Ok((usize, Ipv4Addr)) - The number of bytes received and source address
  • Err(PacketError) - If receiving fails
Source

pub async fn ready(&self, interest: Interest) -> Result<()>

Waits for the socket to become ready for the specified operation.

§Arguments
  • interest - The type of operation to wait for (read/write)

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.