Struct net::icmp::Socket

pub struct Socket<'a> { /* private fields */ }
Expand description

A ICMP socket

An ICMP socket is bound to a specific IcmpEndpoint which may be a specific UDP port to listen for ICMP error messages related to the port or a specific ICMP identifier value. See bind for more details.

Implementations§

§

impl<'a> Socket<'a>

pub fn new( rx_buffer: PacketBuffer<'a, Address>, tx_buffer: PacketBuffer<'a, Address> ) -> Socket<'a>

Create an ICMP socket with the given buffers.

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

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.

pub fn bind<T>(&mut self, endpoint: T) -> Result<(), BindError>where T: Into<Endpoint>,

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::IpListenEndpoint;
use smoltcp::socket::icmp;

let mut icmp_socket = // ...

// Bind to ICMP error responses for UDP packets sent from port 53.
let endpoint = IpListenEndpoint::from(53);
icmp_socket.bind(icmp::Endpoint::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::wire::IpListenEndpoint;
use smoltcp::socket::icmp;

let mut icmp_socket = // ...

// Bind to ICMP messages with the ICMP identifier 0x1234
icmp_socket.bind(icmp::Endpoint::Ident(0x1234)).unwrap();

pub fn can_send(&self) -> bool

Check whether the transmit buffer is full.

pub fn can_recv(&self) -> bool

Check whether the receive buffer is not empty.

pub fn packet_recv_capacity(&self) -> usize

Return the maximum number packets the socket can receive.

pub fn packet_send_capacity(&self) -> usize

Return the maximum number packets the socket can transmit.

pub fn payload_recv_capacity(&self) -> usize

Return the maximum number of bytes inside the recv buffer.

pub fn payload_send_capacity(&self) -> usize

Return the maximum number of bytes inside the transmit buffer.

pub fn is_open(&self) -> bool

Check whether the socket is open.

pub fn send( &mut self, size: usize, endpoint: Address ) -> Result<&mut [u8], SendError>

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.

pub fn send_with<F>( &mut self, max_size: usize, endpoint: Address, f: F ) -> Result<usize, SendError>where F: FnOnce(&mut [u8]) -> usize,

Enqueue a packet to be send to a given remote address and pass the buffer to the provided closure. The closure then returns the size of the data written into the buffer.

Also see send.

pub fn send_slice( &mut self, data: &[u8], endpoint: Address ) -> Result<(), SendError>

Enqueue a packet to be sent to a given remote address, and fill it from a slice.

See also send.

pub fn recv(&mut self) -> Result<(&[u8], Address), RecvError>

Dequeue a packet received from a remote endpoint, and return the IpAddress as well as a pointer to the payload.

This function returns Err(Error::Exhausted) if the receive buffer is empty.

pub fn recv_slice( &mut self, data: &mut [u8] ) -> Result<(usize, Address), RecvError>

Dequeue a packet received from a remote endpoint, copy the payload into the given slice, and return the amount of octets copied as well as the IpAddress

See also recv.

Trait Implementations§

§

impl<'a> AnySocket<'a> for Socket<'a>

§

fn upcast(self) -> Socket<'a>

§

fn downcast<'c>(socket: &'c Socket<'a>) -> Option<&'c Socket<'a>>

§

fn downcast_mut<'c>(socket: &'c mut Socket<'a>) -> Option<&'c mut Socket<'a>>

§

impl<'a> Debug for Socket<'a>

§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Socket<'a>

§

impl<'a> Send for Socket<'a>

§

impl<'a> Sync for Socket<'a>

§

impl<'a> Unpin for Socket<'a>

§

impl<'a> !UnwindSafe for Socket<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V