Skip to main content

IcmpSocket

Struct IcmpSocket 

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

Asynchronous, non-blocking ICMP raw socket.

Wraps a socket2::Socket in tokio::io::unix::AsyncFd so that send and receive operations integrate with the Tokio runtime. Supports both ICMPv4 and ICMPv6; the protocol is selected by the address family of the bind address.

Creating an IcmpSocket requires permission to open raw sockets (e.g. CAP_NET_RAW on Linux, or running as root).

Implementations§

Source§

impl IcmpSocket

Source

pub async fn bind<A: ToIpAddr>(addr: A) -> Result<IcmpSocket>

Create a new ICMP raw socket bound to addr.

The address family of addr (after resolution) determines whether an ICMPv4 or ICMPv6 socket is created. The socket is placed in non-blocking mode and registered with the current Tokio runtime.

Source

pub async fn connect<A: ToIpAddr>(&self, addr: A) -> Result<()>

Connect this socket to addr so that subsequent send/recv calls communicate with that peer only.

Source

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

Wait for the socket to become ready for the given Interest.

Source

pub async fn writable(&self) -> Result<()>

Wait for the socket to become writable.

Source

pub async fn send(&self, buf: &[u8]) -> Result<usize>

Send buf on the socket. Requires that the socket has been connected.

Source

pub async fn readable(&self) -> Result<()>

Wait for the socket to become readable.

Source

pub async fn recv(&self, buf: &mut [MaybeUninit<u8>]) -> Result<usize>

Receive a datagram into buf, returning the number of bytes received.

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.