tcp_ip/
lib.rs

1/*!
2# Example
3```no_run
4#[tokio::main]
5pub async fn main() -> std::io::Result<()> {
6    use tokio::io::AsyncReadExt;
7    let (ip_stack, _ip_stack_send, mut ip_stack_recv) = tcp_ip::ip_stack(tcp_ip::IpStackConfig::default())?;
8    tokio::spawn(async move {
9        loop {
10            // ip_stack_send.send_ip_packet()
11            todo!("Send IP packets to the protocol stack using 'ip_stack_send'")
12        }
13    });
14    tokio::spawn(async move {
15        let mut buf = [0; 65535];
16        loop {
17            match ip_stack_recv.recv(&mut buf).await {
18                Ok(_len) => {}
19                Err(e) => println!("{e:?}"),
20            }
21            todo!("Receive IP packets from the protocol stack using 'ip_stack_recv'")
22        }
23    });
24    let mut tcp_listener = tcp_ip::tcp::TcpListener::bind(ip_stack.clone(), "0.0.0.0:80".parse().unwrap()).await?;
25    loop {
26        let (mut tcp_stream, addr) = tcp_listener.accept().await?;
27        tokio::spawn(async move {
28            let mut buf = [0; 1024];
29            match tcp_stream.read(&mut buf).await {
30                Ok(len) => println!("read:{:?},addr={addr}", &buf[..len]),
31                Err(e) => println!("{e:?}"),
32            }
33        });
34    }
35}
36```
37*/
38
39mod buffer;
40pub mod icmp;
41mod ip_stack;
42pub use ip_stack::*;
43pub mod address;
44pub mod ip;
45pub mod tcp;
46pub mod udp;