ssrlive / lwip

lwIP - A Lightweight TCP/IP stack https://github.com/lwip-tcpip/lwip

Home Page:http://savannah.nongnu.org/projects/lwip/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lwip - A Rust wrapper for lwIP

Version Documentation Download

A netstack for the special purpose of turning packets from/to a TUN interface into TCP streams and UDP packets. It uses lwIP as the backend netstack.

use futures::{SinkExt, StreamExt};

let (stack, mut tcp_listener, udp_socket) = ::lwip::NetStack::new().unwrap();
let (mut stack_sink, mut stack_stream) = stack.split();

// tun device is assumed implementing `Stream` and `Sink`
let (mut tun_sink, mut tun_stream) = tun.split();

// Reads packet from stack and sends to TUN.
tokio::spawn(async move {
    while let Some(pkt) = stack_stream.next().await {
        if let Ok(pkt) = pkt {
            tun_sink.send(pkt).await.unwrap();
        }
    }
});

// Reads packet from TUN and sends to stack.
tokio::spawn(async move {
    while let Some(pkt) = tun_stream.next().await {
        if let Ok(pkt) = pkt {
            stack_sink.send(pkt).await.unwrap();
        }
    }
});

// Extracts TCP connections from stack and sends them to the dispatcher.
tokio::spawn(async move {
    while let Some((stream, local_addr, remote_addr)) = tcp_listener.next().await {
        tokio::spawn(handle_inbound_stream(stream, local_addr, remote_addr));
    }
});

// Receive and send UDP packets between netstack and NAT manager. The NAT
// manager would maintain UDP sessions and send them to the dispatcher.
tokio::spawn(async move {
    handle_inbound_datagram(udp_socket).await;
});

About

lwIP - A Lightweight TCP/IP stack https://github.com/lwip-tcpip/lwip

http://savannah.nongnu.org/projects/lwip/

License:Other


Languages

Language:C 94.7%Language:C# 3.8%Language:Rust 0.5%Language:CMake 0.5%Language:Makefile 0.4%Language:HTML 0.1%Language:Shell 0.1%Language:Perl 0.0%Language:Batchfile 0.0%Language:Objective-C 0.0%