pub struct Pinger { /* private fields */ }Expand description
A Ping struct represents the state of one particular ping instance.
Implementations§
Source§impl Pinger
impl Pinger
Sourcepub fn new(host: IpAddr) -> Result<Pinger, Error>
pub fn new(host: IpAddr) -> Result<Pinger, Error>
Creates a new raw-socket ping instance from IpAddr.
Sourcepub fn with_socket_type(
host: IpAddr,
socket_type: SocketType,
) -> Result<Pinger, Error>
pub fn with_socket_type( host: IpAddr, socket_type: SocketType, ) -> Result<Pinger, Error>
Creates a new ping instance using a specific socket type.
Sourcepub fn with_socket_addr(
target: SocketAddr,
socket_type: SocketType,
) -> Result<Pinger, Error>
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.
Sourcepub fn socket_type(
&mut self,
socket_type: SocketType,
) -> Result<&mut Pinger, Error>
pub fn socket_type( &mut self, socket_type: SocketType, ) -> Result<&mut Pinger, Error>
Changes the socket type and recreates the underlying socket.
Sourcepub fn active_socket_type(&self) -> SocketType
pub fn active_socket_type(&self) -> SocketType
Returns the active socket type.
Sourcepub fn target(&self) -> SocketAddr
pub fn target(&self) -> SocketAddr
Returns the target address.
Sourcepub fn source(&self) -> Option<SocketAddr>
pub fn source(&self) -> Option<SocketAddr>
Returns the configured source address, if one has been bound.
Sourcepub fn bind_source(&mut self, source: SocketAddr) -> Result<&mut Pinger, Error>
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.
Sourcepub fn bind_device(
&mut self,
interface: Option<&[u8]>,
) -> Result<&mut Pinger, Error>
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.
Sourcepub fn identifier(&self) -> u16
pub fn identifier(&self) -> u16
Returns the ICMP identifier.
Sourcepub fn size(&mut self, size: usize) -> &mut Pinger
pub fn size(&mut self, size: usize) -> &mut Pinger
Set the packet payload size in bytes. (default: 56)
Sourcepub fn payload_size(&self) -> usize
pub fn payload_size(&self) -> usize
Returns the default generated payload size in bytes.
Sourcepub fn timeout(&mut self, timeout: Duration) -> &mut Pinger
pub fn timeout(&mut self, timeout: Duration) -> &mut Pinger
Set the timeout of each ping. (default: 2s)
Sourcepub fn timeout_duration(&self) -> Duration
pub fn timeout_duration(&self) -> Duration
Returns the timeout used for each ping.
Sourcepub fn ttl(&mut self, ttl: u32) -> Result<&mut Pinger, Error>
pub fn ttl(&mut self, ttl: u32) -> Result<&mut Pinger, Error>
Set the outgoing IPv4 TTL or IPv6 unicast hop limit.
Sourcepub fn ttl_value(&self) -> Option<u32>
pub fn ttl_value(&self) -> Option<u32>
Returns the configured outgoing IPv4 TTL or IPv6 unicast hop limit.
Sourcepub async fn ping(
&self,
request: impl Into<PingRequest>,
) -> Result<PingResult, Error>
pub async fn ping( &self, request: impl Into<PingRequest>, ) -> Result<PingResult, Error>
Send a ping request with sequence number.
Sourcepub async fn ping_replies(
&self,
request: impl Into<PingRequest>,
) -> Result<Vec<PingResult>, Error>
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.
Sourcepub async fn ping_many(&self, series: PingSeries) -> PingSeriesResult
pub async fn ping_many(&self, series: PingSeries) -> PingSeriesResult
Sends a sequence of ping requests and returns each attempt plus summary statistics.