Skip to main content

Pinger

Struct Pinger 

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

A Ping struct represents the state of one particular ping instance.

Implementations§

Source§

impl Pinger

Source

pub fn new(host: IpAddr) -> Result<Pinger, Error>

Creates a new raw-socket ping instance from IpAddr.

Source

pub fn with_socket_type( host: IpAddr, socket_type: SocketType, ) -> Result<Pinger, Error>

Creates a new ping instance using a specific socket type.

Source

pub fn with_socket_addr( target: SocketAddr, socket_type: SocketType, ) -> Result<Pinger, Error>

Creates a new ping instance using a specific socket address and socket type.

The port is ignored. For IPv6, callers can use this to provide a SocketAddrV6 scope ID, for example when targeting link-local multicast.

Source

pub fn socket_type( &mut self, socket_type: SocketType, ) -> Result<&mut Pinger, Error>

Changes the socket type and recreates the underlying socket.

Source

pub fn active_socket_type(&self) -> SocketType

Returns the active socket type.

Source

pub fn target(&self) -> SocketAddr

Returns the target address.

Source

pub fn source(&self) -> Option<SocketAddr>

Returns the configured source address, if one has been bound.

Source

pub fn bind_source(&mut self, source: SocketAddr) -> Result<&mut Pinger, Error>

Binds the socket to a local source address.

The port is ignored. For IPv6, the scope ID is preserved.

Source

pub fn bind_device( &mut self, interface: Option<&[u8]>, ) -> Result<&mut Pinger, Error>

Sets the value for the SO_BINDTODEVICE option on this socket.

If a socket is bound to an interface, only packets received from that particular interface are processed by the socket. Note that this only works for some socket types, particularly AF_INET sockets.

If interface is None or an empty string it removes the binding.

This function is only available on Fuchsia and Linux.

Source

pub fn ident(&mut self, val: u16) -> &mut Pinger

Set the identification of ICMP.

Source

pub fn identifier(&self) -> u16

Returns the ICMP identifier.

Source

pub fn size(&mut self, size: usize) -> &mut Pinger

Set the packet payload size in bytes. (default: 56)

Source

pub fn payload_size(&self) -> usize

Returns the default generated payload size in bytes.

Source

pub fn timeout(&mut self, timeout: Duration) -> &mut Pinger

Set the timeout of each ping. (default: 2s)

Source

pub fn timeout_duration(&self) -> Duration

Returns the timeout used for each ping.

Source

pub fn ttl(&mut self, ttl: u32) -> Result<&mut Pinger, Error>

Set the outgoing IPv4 TTL or IPv6 unicast hop limit.

Source

pub fn ttl_value(&self) -> Option<u32>

Returns the configured outgoing IPv4 TTL or IPv6 unicast hop limit.

Source

pub async fn ping( &self, request: impl Into<PingRequest>, ) -> Result<PingResult, Error>

Send a ping request with sequence number.

Source

pub async fn ping_replies( &self, request: impl Into<PingRequest>, ) -> Result<Vec<PingResult>, Error>

Send one ping request and collect all matching replies until timeout.

This is useful for multicast targets where more than one host can reply to the same echo request. Unlike Pinger::ping, a timeout after the request is sent is not an error; it ends collection and returns the replies seen so far.

Source

pub async fn ping_many(&self, series: PingSeries) -> PingSeriesResult

Sends a sequence of ping requests and returns each attempt plus summary statistics.

Trait Implementations§

Source§

impl Clone for Pinger

Source§

fn clone(&self) -> Pinger

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Pinger

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.