{"id":19825238,"url":"https://github.com/yaa110/tokio-tun","last_synced_at":"2025-05-16T03:03:05.068Z","repository":{"id":37945378,"uuid":"300800080","full_name":"yaa110/tokio-tun","owner":"yaa110","description":"Asynchronous allocation of TUN/TAP devices in Rust using tokio","archived":false,"fork":false,"pushed_at":"2025-02-20T18:24:47.000Z","size":44,"stargazers_count":88,"open_issues_count":10,"forks_count":32,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-08T13:09:17.720Z","etag":null,"topics":["async","crates","rust","tap","tokio","tun"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/tokio-tun","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yaa110.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-03T05:04:24.000Z","updated_at":"2025-04-06T14:03:06.000Z","dependencies_parsed_at":"2024-09-10T23:32:50.067Z","dependency_job_id":"c69962af-77ec-460f-9c52-a4709235372e","html_url":"https://github.com/yaa110/tokio-tun","commit_stats":{"total_commits":41,"total_committers":8,"mean_commits":5.125,"dds":"0.19512195121951215","last_synced_commit":"363059845cddf8411aa8d5b8dc9c20a44d551087"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaa110%2Ftokio-tun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaa110%2Ftokio-tun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaa110%2Ftokio-tun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaa110%2Ftokio-tun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yaa110","download_url":"https://codeload.github.com/yaa110/tokio-tun/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254459083,"owners_count":22074604,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","crates","rust","tap","tokio","tun"],"created_at":"2024-11-12T11:07:05.967Z","updated_at":"2025-05-16T03:03:00.059Z","avatar_url":"https://github.com/yaa110.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tokio TUN/TAP\n\n[![Build](https://github.com/yaa110/tokio-tun/workflows/Build/badge.svg)](https://github.com/yaa110/tokio-tun/actions) [![crates.io](https://img.shields.io/crates/v/tokio-tun.svg)](https://crates.io/crates/tokio-tun) [![Documentation](https://img.shields.io/badge/docs-tokio--tun-blue.svg)](https://docs.rs/tokio-tun) [![examples](https://img.shields.io/badge/examples-tokio--tun-blue.svg)](examples)\n\nAsynchronous allocation of TUN/TAP devices in Rust using [`tokio`](https://crates.io/crates/tokio). Use [async-tun](https://crates.io/crates/async-tun) for `async-std` version.\n\n## Getting Started\n\n- Create a tun device using `Tun::builder()` and read from it in a loop:\n\n```rust\n#[tokio::main]\nasync fn main() {\n    let tun = Arc::new(\n        Tun::builder()\n            .name(\"\")            // if name is empty, then it is set by kernel.\n            .tap()               // uses TAP instead of TUN (default).\n            .packet_info()       // avoids setting IFF_NO_PI.\n            .up()                // or set it up manually using `sudo ip link set \u003ctun-name\u003e up`.\n            .build()\n            .unwrap()\n            .pop()\n            .unwrap(),\n    );\n\n    println!(\"tun created, name: {}, fd: {}\", tun.name(), tun.as_raw_fd());\n\n    let (mut reader, mut _writer) = tokio::io::split(tun);\n\n    // Writer: simply clone Arced Tun.\n    let tun_c = tun.clone();\n    tokio::spawn(async move{\n        let buf = b\"data to be written\";\n        tun_c.send_all(buf).await.unwrap();\n    });\n\n    // Reader\n    let mut buf = [0u8; 1024];\n    loop {\n        let n = tun.recv(\u0026mut buf).await.unwrap();\n        println!(\"reading {} bytes: {:?}\", n, \u0026buf[..n]);\n    }\n}\n```\n\n- Run the code using `sudo`:\n\n```bash\nsudo -E $(which cargo) run\n```\n\n- Set the address of device (address and netmask could also be set using `TunBuilder`):\n\n```bash\nsudo ip a add 10.0.0.1/24 dev \u003ctun-name\u003e\n```\n\n- Ping to read packets:\n\n```bash\nping 10.0.0.2\n```\n\n- Display devices and analyze the network traffic:\n\n```bash\nip tuntap\nsudo tshark -i \u003ctun-name\u003e\n```\n\n## Supported Platforms\n\n- [x] Linux\n- [ ] FreeBSD\n- [ ] Android\n- [ ] OSX\n- [ ] iOS\n- [ ] Windows\n\n## Examples\n\n- [`read`](examples/read.rs): Split tun to (reader, writer) pair and read packets from reader.\n- [`read-mq`](examples/read-mq.rs): Read from multi-queue tun using `tokio::select!`.\n\n```bash\nsudo -E $(which cargo) run --example read\nsudo -E $(which cargo) run --example read-mq\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaa110%2Ftokio-tun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyaa110%2Ftokio-tun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaa110%2Ftokio-tun/lists"}