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 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 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 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 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 async fn ping(&self, seq_cnt: u16) -> Result<PingResult, Error>
pub async fn ping(&self, seq_cnt: u16) -> Result<PingResult, Error>
Send a ping request with sequence number.
Sourcepub async fn ping_replies(&self, seq_cnt: u16) -> Result<Vec<PingResult>, Error>
pub async fn ping_replies(&self, seq_cnt: u16) -> 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.