[−][src]Struct icmp::IcmpSocket
An Internet Control Message Protocol socket.
This is an implementation of a bound ICMP socket. This supports both IPv4 and IPv6 addresses, and there is no corresponding notion of a server because ICMP is a datagram protocol.
use icmp; use std::net::{IpAddr, Ipv4Addr}; let localhost_v4 = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)); let ping = icmp::IcmpSocket::connect(localhost_v4); let mut ping = ping.unwrap(); let payload: &[u8] = &[1, 2]; let result = ping.send(payload); assert_eq!(result.unwrap(), 2);
In case you received an error message, you need to enable the correct capabilites:
cargo build
sudo setcap cap_net_raw+ep ./target/debug/PROJECT_NAME
cargo run
Methods
impl IcmpSocket
[src]
pub fn connect(addr: IpAddr) -> Result<IcmpSocket>
[src]
Connect socket to addr
pub fn recv(&self, buf: &mut [u8]) -> Result<usize>
[src]
Receives data from the socket. On success, returns the number of bytes read.
pub fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, IpAddr)>
[src]
Receives data from the socket. On success, returns the number of bytes read and the address from whence the data came.
pub fn send(&mut self, buf: &[u8]) -> Result<usize>
[src]
Sends data on the socket to the remote address to which it is connected.
The connect
method will connect this socket to a remote address. This
method will fail if the socket is not connected.
pub fn set_read_timeout(&self, dur: Option<Duration>) -> Result<()>
[src]
Sets the read timeout to the timeout specified.
If the value specified is None
, then read
calls will block
indefinitely. It is an error to pass the zero Duration
to this
method.
Note
Platforms may return a different error code whenever a read times out as
a result of setting this option. For example Unix typically returns an
error of the kind WouldBlock
, but Windows may return TimedOut
.
pub fn set_write_timeout(&self, dur: Option<Duration>) -> Result<()>
[src]
Sets the write timeout to the timeout specified.
If the value specified is None
, then write
calls will block
indefinitely. It is an error to pass the zero Duration
to this
method.
Note
Platforms may return a different error code whenever a write times out
as a result of setting this option. For example Unix typically returns
an error of the kind WouldBlock
, but Windows may return TimedOut
.
pub fn read_timeout(&self) -> Result<Option<Duration>>
[src]
Returns the read timeout of this socket.
If the timeout is None
, then read
calls will block indefinitely.
pub fn write_timeout(&self) -> Result<Option<Duration>>
[src]
Returns the write timeout of this socket.
If the timeout is None
, then write
calls will block indefinitely.
pub fn set_ttl(&self, ttl: u32) -> Result<()>
[src]
Sets the value for the IP_TTL
option on this socket.
This value sets the time-to-live field that is used in every packet sent from this socket.
pub fn ttl(&self) -> Result<u32>
[src]
Gets the value of the IP_TTL
option for this socket.
For more information about this option, see set_ttl
.
pub fn set_broadcast(&self, broadcast: bool) -> Result<()>
[src]
Sets the value of the SO_BROADCAST option for this socket.
When enabled, this socket is allowed to send packets to a broadcast address.
pub fn broadcast(&self) -> Result<bool>
[src]
Gets the value of the SO_BROADCAST
option for this socket.
For more information about this option, see
set_broadcast
.
pub fn set_qos(&self, qos: u8) -> Result<()>
[src]
Sets the QoS value of the IP_TOS
/IPV6_TCLASS
option for this socket.
This value sets the TOS/DSCP field that is used in every packet sent from this socket.
pub fn qos(&self) -> Result<u8>
[src]
Gets the value of the IP_TOS
/IPV6_TCLASS
option for this socket.
For more information about this option, see
set_qos
.
Auto Trait Implementations
impl Send for IcmpSocket
impl Sync for IcmpSocket
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,