Skip to main content

Crate ts_netstack_smoltcp

Crate ts_netstack_smoltcp 

Source
Expand description

§ts_netstack_smoltcp

Userspace netstack built as an opinionated wrapper around smoltcp.

§Example

Compare the examples from ts_netstack_smoltcp_core and ts_netstack_smoltcp_socket:

#![cfg(feature = "std")]

extern crate ts_netstack_smoltcp as netstack;

use core::time::Duration;
use netstack::{netcore::smoltcp, HasChannel, CreateSocket};

fn main() {
    let (mut stack, mut pipe) = netstack::piped(Default::default());
    let command_channel = stack.command_channel();

    // Run the netstack in the background to process the socket commands:
    stack.spawn_threaded(Duration::from_millis(10));

    // Bind a socket and send a packet:
    let sock = command_channel.udp_bind_blocking(([127, 0, 0, 1], 1000).into()).unwrap();
    sock.send_to_blocking(([1, 2, 3, 4], 80).into(), b"hello");

    // Receive the packet from the pipe device:
    let packet = pipe.rx.recv().unwrap();
    println!("packet: {packet:?}");

    // Sanity-check that the packet we got back is shaped correctly:
    assert_eq!(packet.len(), smoltcp::wire::IPV4_HEADER_LEN + smoltcp::wire::UDP_HEADER_LEN + b"hello".len());
    assert_eq!(packet[0] >> 4, 4); // ipv4 packet
    assert!(packet.ends_with(b"hello"));
}

Re-exports§

pub extern crate ts_netstack_smoltcp_core as netcore;
pub extern crate ts_netstack_smoltcp_socket as netsock;

Structs§

CoreStack
Internally i/o free userspace network stack built around smoltcp.
Netstack
A userspace network stack.
WakingPipe
Bidirectional pipe carrying byte buffer payloads.
WakingPipeDev
Wrapper around WakingPipe to implement smoltcp::phy::Device.
WakingPipeReceiver
A flume::Receiver wrapped to support AsyncWakeDevice.
WakingPipeSender
A flume::Sender that wakes a remote WakingPipeReceiver when a message is sent.

Traits§

CreateSocket
API for creating sockets over a HasChannel.
HasChannel
Helper methods for types that can provide a Channel.

Functions§

run
Run the netstack indefinitely.
run_blocking
Run the netstack in the current thread.

Type Aliases§

Clock
A function that yields “now” Instants.