smoltcp::iface

Struct Interface

Source
pub struct Interface { /* private fields */ }
Expand description

A network interface.

The network interface logically owns a number of other data structures; to avoid a dependency on heap allocation, it instead owns a BorrowMut<[T]>, which can be a &mut [T], or Vec<T> if a heap is available.

Implementations§

Source§

impl Interface

Source

pub fn new<D>(config: Config, device: &mut D, now: Instant) -> Self
where D: Device + ?Sized,

Create a network interface using the previously provided configuration.

§Panics

This function panics if the [Config::hardware_address] does not match the medium of the device.

Source

pub fn context(&mut self) -> &mut InterfaceInner

Get the socket context.

The context is needed for some socket methods.

Source

pub fn hardware_addr(&self) -> HardwareAddress

Get the HardwareAddress address of the interface.

§Panics

This function panics if the medium is not Ethernet or Ieee802154.

Source

pub fn set_hardware_addr(&mut self, addr: HardwareAddress)

Set the HardwareAddress address of the interface.

§Panics

This function panics if the address is not unicast, and if the medium is not Ethernet or Ieee802154.

Source

pub fn ip_addrs(&self) -> &[IpCidr]

Get the IP addresses of the interface.

Source

pub fn ipv4_addr(&self) -> Option<Ipv4Address>

Get the first IPv4 address if present.

Source

pub fn ipv6_addr(&self) -> Option<Ipv6Address>

Get the first IPv6 address if present.

Source

pub fn get_source_address(&self, dst_addr: &IpAddress) -> Option<IpAddress>

Get an address from the interface that could be used as source address. For IPv4, this is the first IPv4 address from the list of addresses. For IPv6, the address is based on the destination address and uses RFC6724 for selecting the source address.

Source

pub fn get_source_address_ipv4( &self, dst_addr: &Ipv4Address, ) -> Option<Ipv4Address>

Get an address from the interface that could be used as source address. This is the first IPv4 address from the list of addresses in the interface.

Source

pub fn get_source_address_ipv6( &self, dst_addr: &Ipv6Address, ) -> Option<Ipv6Address>

Get an address from the interface that could be used as source address. The selection is based on RFC6724.

Source

pub fn update_ip_addrs<F: FnOnce(&mut Vec<IpCidr, IFACE_MAX_ADDR_COUNT>)>( &mut self, f: F, )

Update the IP addresses of the interface.

§Panics

This function panics if any of the addresses are not unicast.

Source

pub fn has_ip_addr<T: Into<IpAddress>>(&self, addr: T) -> bool

Check whether the interface has the given IP address assigned.

Source

pub fn routes(&self) -> &Routes

Source

pub fn routes_mut(&mut self) -> &mut Routes

Source

pub fn set_any_ip(&mut self, any_ip: bool)

Enable or disable the AnyIP capability.

AnyIP allowins packets to be received locally on IPv4 addresses other than the interface’s configured [ip_addrs]. When AnyIP is enabled and a route prefix in routes specifies one of the interface’s ip_addrs as its gateway, the interface will accept packets addressed to that prefix.

§IPv6

This option is not available or required for IPv6 as packets sent to the interface are not filtered by IPv6 address.

Source

pub fn any_ip(&self) -> bool

Get whether AnyIP is enabled.

See set_any_ip for details on AnyIP

Source

pub fn reassembly_timeout(&self) -> Duration

Get the packet reassembly timeout.

Source

pub fn set_reassembly_timeout(&mut self, timeout: Duration)

Set the packet reassembly timeout.

Source

pub fn poll<D>( &mut self, timestamp: Instant, device: &mut D, sockets: &mut SocketSet<'_>, ) -> bool
where D: Device + ?Sized,

Transmit packets queued in the given sockets, and receive packets queued in the device.

This function returns a boolean value indicating whether any packets were processed or emitted, and thus, whether the readiness of any socket might have changed.

Source

pub fn poll_at( &mut self, timestamp: Instant, sockets: &SocketSet<'_>, ) -> Option<Instant>

Return a soft deadline for calling poll the next time. The Instant returned is the time at which you should call poll next. It is harmless (but wastes energy) to call it before the Instant, and potentially harmful (impacting quality of service) to call it after the Instant

Source

pub fn poll_delay( &mut self, timestamp: Instant, sockets: &SocketSet<'_>, ) -> Option<Duration>

Return an advisory wait time for calling poll the next time. The Duration returned is the time left to wait before calling poll next. It is harmless (but wastes energy) to call it before the Duration has passed, and potentially harmful (impacting quality of service) to call it after the Duration has passed.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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

Source§

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.