morpheus_network::stack

Struct NetInterface

Source
pub struct NetInterface<D: NetworkDevice> {
    device: DeviceAdapter<D>,
    iface: Interface,
    sockets: SocketSet<'static>,
    dhcp_handle: Option<SocketHandle>,
    dns_handle: SocketHandle,
    state: NetState,
    gateway: Option<Ipv4Address>,
    dns: Option<Ipv4Address>,
    last_poll_ms: u64,
}
Expand description

Full network interface with IP stack.

Wraps a NetworkDevice with complete smoltcp integration.

Fields§

§device: DeviceAdapter<D>

The underlying device adapter.

§iface: Interface

smoltcp interface.

§sockets: SocketSet<'static>

Socket set.

§dhcp_handle: Option<SocketHandle>

DHCP socket handle (if using DHCP).

§dns_handle: SocketHandle

DNS socket handle.

§state: NetState

Current state.

§gateway: Option<Ipv4Address>

Configured gateway.

§dns: Option<Ipv4Address>

Configured DNS server.

§last_poll_ms: u64

Last poll timestamp (milliseconds).

Implementations§

Source§

impl<D: NetworkDevice> NetInterface<D>

Source

pub fn new(device: D, config: NetConfig) -> Self

Create a new network interface.

§Arguments
  • device - The network device to use
  • config - IP configuration (DHCP or static)
Source

pub fn state(&self) -> NetState

Get current state.

Source

pub fn has_ip(&self) -> bool

Check if interface has an IP address configured.

Source

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

Get the current IPv4 address (if configured).

Source

pub fn gateway(&self) -> Option<Ipv4Addr>

Get the gateway address.

Source

pub fn dns(&self) -> Option<Ipv4Addr>

Get the DNS server address.

Source

pub fn start_dns_query(&mut self, hostname: &str) -> Result<QueryHandle>

Start a DNS query for a hostname. Returns a query handle.

Source

pub fn get_dns_result( &mut self, handle: QueryHandle, ) -> Result<Option<Ipv4Addr>>

Check DNS query result. Returns Ok(Some(ip)) if resolved, Ok(None) if pending, Err if failed.

Source

pub fn mac_address(&self) -> [u8; 6]

Get the MAC address.

Source

pub fn poll(&mut self, timestamp_ms: u64) -> bool

Poll the interface - must be called regularly.

Returns true if any socket activity occurred.

Source

pub fn tcp_socket(&mut self) -> Result<SocketHandle>

Create a TCP socket and return its handle.

Source

pub fn tcp_connect( &mut self, handle: SocketHandle, remote_ip: Ipv4Addr, remote_port: u16, ) -> Result<()>

Connect a TCP socket to a remote endpoint.

Source

pub fn tcp_is_connected(&self, handle: SocketHandle) -> bool

Check if a TCP socket is connected.

Source

pub fn tcp_can_send(&self, handle: SocketHandle) -> bool

Check if a TCP socket can send data.

Source

pub fn tcp_can_recv(&self, handle: SocketHandle) -> bool

Check if a TCP socket can receive data.

Source

pub fn tcp_send(&mut self, handle: SocketHandle, data: &[u8]) -> Result<usize>

Send data on a TCP socket.

Source

pub fn tcp_recv( &mut self, handle: SocketHandle, buffer: &mut [u8], ) -> Result<usize>

Receive data from a TCP socket.

Source

pub fn tcp_close(&mut self, handle: SocketHandle)

Close a TCP socket.

Source

pub fn remove_socket(&mut self, handle: SocketHandle)

Remove a socket from the set.

Source

pub fn tcp_state(&self, handle: SocketHandle) -> TcpState

Get TCP socket state.

Source

fn ephemeral_port(&self) -> u16

Generate an ephemeral port number.

Source

pub fn device(&self) -> &D

Get reference to the underlying device.

Source

pub fn device_mut(&mut self) -> &mut D

Get mutable reference to the underlying device.

Auto Trait Implementations§

§

impl<D> Freeze for NetInterface<D>
where D: Freeze,

§

impl<D> RefUnwindSafe for NetInterface<D>
where D: RefUnwindSafe,

§

impl<D> Send for NetInterface<D>
where D: Send,

§

impl<D> Sync for NetInterface<D>
where D: Sync,

§

impl<D> Unpin for NetInterface<D>
where D: Unpin,

§

impl<D> !UnwindSafe for NetInterface<D>

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.