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: Interfacesmoltcp interface.
sockets: SocketSet<'static>Socket set.
dhcp_handle: Option<SocketHandle>DHCP socket handle (if using DHCP).
dns_handle: SocketHandleDNS socket handle.
state: NetStateCurrent state.
gateway: Option<Ipv4Address>Configured gateway.
dns: Option<Ipv4Address>Configured DNS server.
last_poll_ms: u64Last poll timestamp (milliseconds).
Implementations§
Source§impl<D: NetworkDevice> NetInterface<D>
impl<D: NetworkDevice> NetInterface<D>
Sourcepub fn new(device: D, config: NetConfig) -> Self
pub fn new(device: D, config: NetConfig) -> Self
Create a new network interface.
§Arguments
device- The network device to useconfig- IP configuration (DHCP or static)
Sourcepub fn start_dns_query(&mut self, hostname: &str) -> Result<QueryHandle>
pub fn start_dns_query(&mut self, hostname: &str) -> Result<QueryHandle>
Start a DNS query for a hostname. Returns a query handle.
Sourcepub fn get_dns_result(
&mut self,
handle: QueryHandle,
) -> Result<Option<Ipv4Addr>>
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.
Sourcepub fn mac_address(&self) -> [u8; 6]
pub fn mac_address(&self) -> [u8; 6]
Get the MAC address.
Sourcepub fn poll(&mut self, timestamp_ms: u64) -> bool
pub fn poll(&mut self, timestamp_ms: u64) -> bool
Poll the interface - must be called regularly.
Returns true if any socket activity occurred.
Sourcepub fn tcp_socket(&mut self) -> Result<SocketHandle>
pub fn tcp_socket(&mut self) -> Result<SocketHandle>
Create a TCP socket and return its handle.
Sourcepub fn tcp_connect(
&mut self,
handle: SocketHandle,
remote_ip: Ipv4Addr,
remote_port: u16,
) -> Result<()>
pub fn tcp_connect( &mut self, handle: SocketHandle, remote_ip: Ipv4Addr, remote_port: u16, ) -> Result<()>
Connect a TCP socket to a remote endpoint.
Sourcepub fn tcp_is_connected(&self, handle: SocketHandle) -> bool
pub fn tcp_is_connected(&self, handle: SocketHandle) -> bool
Check if a TCP socket is connected.
Sourcepub fn tcp_can_send(&self, handle: SocketHandle) -> bool
pub fn tcp_can_send(&self, handle: SocketHandle) -> bool
Check if a TCP socket can send data.
Sourcepub fn tcp_can_recv(&self, handle: SocketHandle) -> bool
pub fn tcp_can_recv(&self, handle: SocketHandle) -> bool
Check if a TCP socket can receive data.
Sourcepub fn tcp_send(&mut self, handle: SocketHandle, data: &[u8]) -> Result<usize>
pub fn tcp_send(&mut self, handle: SocketHandle, data: &[u8]) -> Result<usize>
Send data on a TCP socket.
Sourcepub fn tcp_recv(
&mut self,
handle: SocketHandle,
buffer: &mut [u8],
) -> Result<usize>
pub fn tcp_recv( &mut self, handle: SocketHandle, buffer: &mut [u8], ) -> Result<usize>
Receive data from a TCP socket.
Sourcepub fn remove_socket(&mut self, handle: SocketHandle)
pub fn remove_socket(&mut self, handle: SocketHandle)
Remove a socket from the set.
Sourcefn ephemeral_port(&self) -> u16
fn ephemeral_port(&self) -> u16
Generate an ephemeral port number.
Sourcepub fn device_mut(&mut self) -> &mut D
pub fn device_mut(&mut self) -> &mut D
Get mutable reference to the underlying device.