ts_netstack_smoltcp 0.2.0

userspace netstack built on smoltcp
docs.rs failed to build ts_netstack_smoltcp-0.2.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

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"));
}