Struct NetworkStack

Source
pub struct NetworkStack<'a, Device, Clock>
where Device: Device, Clock: Clock, u32: From<Clock::T>,
{ /* private fields */ }
Expand description

Network abstraction layer for smoltcp.

Implementations§

Source§

impl<'a, Device, Clock> NetworkStack<'a, Device, Clock>
where Device: Device, Clock: Clock, u32: From<Clock::T>,

Source

pub fn new( stack: Interface, device: Device, sockets: SocketSet<'a>, clock: Clock, ) -> Self

Construct a new network stack.

§Note

This implementation only supports up to 16 usable sockets.

Any handles provided to this function must not be used after constructing the network stack.

This implementation currently only supports IPv4.

§Args
  • stack - The ethernet interface to construct the network stack from.
  • clock - A clock to use for determining network time.
§Returns

A embedded_nal compatible network stack.

Source

pub fn seed_random_port(&mut self, seed: &[u8])

Seed the TCP port randomizer.

§Args
  • seed - A seed of random data to use for randomizing local TCP port selection.
Source

pub fn poll(&mut self) -> Result<bool, Error>

Poll the network stack for potential updates.

§Returns

A boolean indicating if the network stack updated in any way.

Source

pub fn close_sockets(&mut self)

Force-close all sockets.

Handle a disconnection of the physical interface.

Source

pub fn interface(&self) -> &Interface

Access the underlying network interface.

Source

pub fn interface_mut(&mut self) -> &mut Interface

Mutably access the underlying network interface.

§Note

Modification of the underlying network interface may unintentionally interfere with operation of this library (e.g. through reset, modification of IP addresses, etc.). Mutable access to the interface should be done with care.

Trait Implementations§

Source§

impl<Device, Clock> Dns for NetworkStack<'_, Device, Clock>
where Device: Device, Clock: Clock, u32: From<Clock::T>,

Source§

type Error = NetworkError

The type returned when we have an error
Source§

fn get_host_by_name( &mut self, hostname: &str, _addr_type: AddrType, ) -> Result<IpAddr, Self::Error>

Resolve the first ip address of a host, given its hostname and a desired address record type to look for
Source§

fn get_host_by_address( &mut self, _addr: IpAddr, _: &mut [u8], ) -> Result<usize, Error<Self::Error>>

Resolve the hostname of a host, given its ip address. Read more
Source§

impl<Device, Clock> TcpClientStack for NetworkStack<'_, Device, Clock>
where Device: Device, Clock: Clock, u32: From<Clock::T>,

Source§

type Error = NetworkError

The type returned when we have an error
Source§

type TcpSocket = SocketHandle

The type returned when we create a new TCP socket
Source§

fn socket(&mut self) -> Result<SocketHandle, NetworkError>

Open a socket for usage as a TCP client. Read more
Source§

fn connect( &mut self, socket: &mut SocketHandle, remote: SocketAddr, ) -> Result<(), NetworkError>

Connect to the given remote host and port. Read more
Source§

fn send( &mut self, socket: &mut SocketHandle, buffer: &[u8], ) -> Result<usize, NetworkError>

Write to the stream. Read more
Source§

fn receive( &mut self, socket: &mut SocketHandle, buffer: &mut [u8], ) -> Result<usize, NetworkError>

Receive data from the stream. Read more
Source§

fn close(&mut self, socket: SocketHandle) -> Result<(), NetworkError>

Close an existing TCP socket.
Source§

impl<Device, Clock> UdpClientStack for NetworkStack<'_, Device, Clock>
where Device: Device, Clock: Clock, u32: From<Clock::T>,

Source§

type Error = NetworkError

The type returned when we have an error
Source§

type UdpSocket = UdpSocket

The type returned when we create a new UDP socket
Source§

fn socket(&mut self) -> Result<UdpSocket, NetworkError>

Allocate a socket for further use.
Source§

fn connect( &mut self, socket: &mut UdpSocket, remote: SocketAddr, ) -> Result<(), NetworkError>

Connect a UDP socket with a peer using a dynamically selected port. Read more
Source§

fn send( &mut self, socket: &mut UdpSocket, buffer: &[u8], ) -> Result<(), NetworkError>

Send a datagram to the remote host. Read more
Source§

fn receive( &mut self, socket: &mut UdpSocket, buffer: &mut [u8], ) -> Result<(usize, SocketAddr), NetworkError>

Read a datagram the remote host has sent to us. Read more
Source§

fn close(&mut self, socket: UdpSocket) -> Result<(), NetworkError>

Close an existing UDP socket.
Source§

impl<Device, Clock> UdpFullStack for NetworkStack<'_, Device, Clock>
where Device: Device, Clock: Clock, u32: From<Clock::T>,

Source§

fn bind( &mut self, socket: &mut UdpSocket, local_port: u16, ) -> Result<(), NetworkError>

Bind a UDP socket to a specific port.

Source§

fn send_to( &mut self, socket: &mut Self::UdpSocket, remote: SocketAddr, buffer: &[u8], ) -> Result<(), NetworkError>

Send a packet to a remote host/port.

Auto Trait Implementations§

§

impl<'a, Device, Clock> Freeze for NetworkStack<'a, Device, Clock>
where u32: Sized, Device: Freeze, Clock: Freeze, <Clock as Clock>::T: Freeze,

§

impl<'a, Device, Clock> RefUnwindSafe for NetworkStack<'a, Device, Clock>
where u32: Sized, Device: RefUnwindSafe, Clock: RefUnwindSafe, <Clock as Clock>::T: RefUnwindSafe,

§

impl<'a, Device, Clock> Send for NetworkStack<'a, Device, Clock>
where u32: Sized, Device: Send, Clock: Send, <Clock as Clock>::T: Send,

§

impl<'a, Device, Clock> Sync for NetworkStack<'a, Device, Clock>
where u32: Sized, Device: Sync, Clock: Sync, <Clock as Clock>::T: Sync,

§

impl<'a, Device, Clock> Unpin for NetworkStack<'a, Device, Clock>
where u32: Sized, Device: Unpin, Clock: Unpin, <Clock as Clock>::T: Unpin,

§

impl<'a, Device, Clock> !UnwindSafe for NetworkStack<'a, Device, Clock>

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.