Struct smoltcp::socket::IcmpSocket
source · pub struct IcmpSocket<'a> { /* private fields */ }
Expand description
A ICMP socket
An ICMP socket is bound to a specific IcmpEndpoint which may be a sepecific UDP port to listen for ICMP error messages related to the port or a specific ICMP identifier value. See bind for more details.
Implementations§
source§impl<'a> IcmpSocket<'a>
impl<'a> IcmpSocket<'a>
sourcepub fn new(
rx_buffer: IcmpSocketBuffer<'a>,
tx_buffer: IcmpSocketBuffer<'a>
) -> IcmpSocket<'a>
pub fn new(
rx_buffer: IcmpSocketBuffer<'a>,
tx_buffer: IcmpSocketBuffer<'a>
) -> IcmpSocket<'a>
Create an ICMP socket with the given buffers.
sourcepub fn register_recv_waker(&mut self, waker: &Waker)
pub fn register_recv_waker(&mut self, waker: &Waker)
Register a waker for receive operations.
The waker is woken on state changes that might affect the return value
of recv
method calls, such as receiving data, or the socket closing.
Notes:
- Only one waker can be registered at a time. If another waker was previously registered, it is overwritten and will no longer be woken.
- The Waker is woken only once. Once woken, you must register it again to receive more wakes.
- “Spurious wakes” are allowed: a wake doesn’t guarantee the result of
recv
has necessarily changed.
sourcepub fn register_send_waker(&mut self, waker: &Waker)
pub fn register_send_waker(&mut self, waker: &Waker)
Register a waker for send operations.
The waker is woken on state changes that might affect the return value
of send
method calls, such as space becoming available in the transmit
buffer, or the socket closing.
Notes:
- Only one waker can be registered at a time. If another waker was previously registered, it is overwritten and will no longer be woken.
- The Waker is woken only once. Once woken, you must register it again to receive more wakes.
- “Spurious wakes” are allowed: a wake doesn’t guarantee the result of
send
has necessarily changed.
sourcepub fn hop_limit(&self) -> Option<u8>
pub fn hop_limit(&self) -> Option<u8>
Return the time-to-live (IPv4) or hop limit (IPv6) value used in outgoing packets.
See also the set_hop_limit method
sourcepub fn set_hop_limit(&mut self, hop_limit: Option<u8>)
pub fn set_hop_limit(&mut self, hop_limit: Option<u8>)
Set the time-to-live (IPv4) or hop limit (IPv6) value used in outgoing packets.
A socket without an explicitly set hop limit value uses the default IANA recommended value (64).
Panics
This function panics if a hop limit value of 0 is given. See RFC 1122 § 3.2.1.7.
sourcepub fn bind<T: Into<Endpoint>>(&mut self, endpoint: T) -> Result<()>
pub fn bind<T: Into<Endpoint>>(&mut self, endpoint: T) -> Result<()>
Bind the socket to the given endpoint.
This function returns Err(Error::Illegal)
if the socket was open
(see is_open), and Err(Error::Unaddressable)
if endpoint
is unspecified (see is_specified).
Examples
Bind to ICMP Error messages associated with a specific UDP port:
To recv ICMP error messages that are associated with a specific local UDP port, the socket may be bound to a given port using IcmpEndpoint::Udp. This may be useful for applications using UDP attempting to detect and/or diagnose connection problems.
use smoltcp::wire::IpEndpoint;
use smoltcp::socket::IcmpEndpoint;
let mut icmp_socket = // ...
// Bind to ICMP error responses for UDP packets sent from port 53.
let endpoint = IpEndpoint::from(53);
icmp_socket.bind(IcmpEndpoint::Udp(endpoint)).unwrap();
Bind to a specific ICMP identifier:
To send and recv ICMP packets that are not associated with a specific UDP port, the socket may be bound to a specific ICMP identifier using IcmpEndpoint::Ident. This is useful for sending and receiving Echo Request/Reply messages.
use smoltcp::socket::IcmpEndpoint;
let mut icmp_socket = // ...
// Bind to ICMP messages with the ICMP identifier 0x1234
icmp_socket.bind(IcmpEndpoint::Ident(0x1234)).unwrap();
sourcepub fn packet_recv_capacity(&self) -> usize
pub fn packet_recv_capacity(&self) -> usize
Return the maximum number packets the socket can receive.
sourcepub fn packet_send_capacity(&self) -> usize
pub fn packet_send_capacity(&self) -> usize
Return the maximum number packets the socket can transmit.
sourcepub fn payload_recv_capacity(&self) -> usize
pub fn payload_recv_capacity(&self) -> usize
Return the maximum number of bytes inside the recv buffer.
sourcepub fn payload_send_capacity(&self) -> usize
pub fn payload_send_capacity(&self) -> usize
Return the maximum number of bytes inside the transmit buffer.
sourcepub fn send(&mut self, size: usize, endpoint: IpAddress) -> Result<&mut [u8]>
pub fn send(&mut self, size: usize, endpoint: IpAddress) -> Result<&mut [u8]>
Enqueue a packet to be sent to a given remote address, and return a pointer to its payload.
This function returns Err(Error::Exhausted)
if the transmit buffer is full,
Err(Error::Truncated)
if the requested size is larger than the packet buffer
size, and Err(Error::Unaddressable)
if the remote address is unspecified.
sourcepub fn send_slice(&mut self, data: &[u8], endpoint: IpAddress) -> Result<()>
pub fn send_slice(&mut self, data: &[u8], endpoint: IpAddress) -> Result<()>
Enqueue a packet to be sent to a given remote address, and fill it from a slice.
See also send.