Crate tcp_ip

Source
Expand description

§Example

#[tokio::main]
pub async fn main() -> std::io::Result<()> {
    use tokio::io::AsyncReadExt;
    let (ip_stack, _ip_stack_send, mut ip_stack_recv) = tcp_ip::ip_stack(tcp_ip::IpStackConfig::default())?;
    tokio::spawn(async move {
        loop {
            // ip_stack_send.send_ip_packet()
            todo!("Send IP packets to the protocol stack using 'ip_stack_send'")
        }
    });
    tokio::spawn(async move {
        let mut buf = [0; 65535];
        loop {
            match ip_stack_recv.recv(&mut buf).await {
                Ok(_len) => {}
                Err(e) => println!("{e:?}"),
            }
            todo!("Receive IP packets from the protocol stack using 'ip_stack_recv'")
        }
    });
    let mut tcp_listener = tcp_ip::tcp::TcpListener::bind(ip_stack.clone(), "0.0.0.0:80".parse().unwrap()).await?;
    loop {
        let (mut tcp_stream, addr) = tcp_listener.accept().await?;
        tokio::spawn(async move {
            let mut buf = [0; 1024];
            match tcp_stream.read(&mut buf).await {
                Ok(len) => println!("read:{:?},addr={addr}", &buf[..len]),
                Err(e) => println!("{e:?}"),
            }
        });
    }
}

Modules§

address
icmp
ip
tcp
udp

Structs§

IpStack
Context information of protocol stack
IpStackConfig
Configure the protocol stack
IpStackRecv
Receive IP packets from the protocol stack using IpStackRecv
IpStackSend
Send IP packets to the protocol stack using IpStackSend
SafeRoutes

Functions§

ip_stack
Create a user-space protocol stack.