All Projects → yaa110 → tokio-tun

yaa110 / tokio-tun

Licence: other
Asynchronous allocation of TUN/TAP devices in Rust using tokio

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to tokio-tun

ip2socks
ip flow to socks, support tun and tap.
Stars: ✭ 35 (+105.88%)
Mutual labels:  tap, tun
MysteryCrate
PLUGIN ARCHIVED. USE https://github.com/DaPigGuy/PiggyCrates instead!
Stars: ✭ 30 (+76.47%)
Mutual labels:  tap, crates
net-protocol
golang模拟内核协议栈 实现链路层、网络层、传输层、应用层 用户态协议栈 ,基于虚拟网卡TUN/TAP
Stars: ✭ 129 (+658.82%)
Mutual labels:  tap, tun
nano-rs
An implementation of Nano in Rust using Tokio
Stars: ✭ 29 (+70.59%)
Mutual labels:  tokio
txm
Markdown code example tester; language-agnostic
Stars: ✭ 19 (+11.76%)
Mutual labels:  tap
twitchchat
interface to the irc portion of Twitch's chat
Stars: ✭ 80 (+370.59%)
Mutual labels:  tokio
TAP
A Swift package for the Test Anything Protocol (v13)
Stars: ✭ 21 (+23.53%)
Mutual labels:  tap
sway-alttab
Simple Alt-Tab daemon for SwayWM/i3. Switches back to previous focused window on Alt-Tab or SIGUSR1
Stars: ✭ 36 (+111.76%)
Mutual labels:  crates
crate-trends
🦀Visualize Rust Package: Crates comparison website
Stars: ✭ 14 (-17.65%)
Mutual labels:  crates
unitest
🌎 Seamless node and browser unit testing with code coverage
Stars: ✭ 28 (+64.71%)
Mutual labels:  tap
tap-html
📊 an html tap reporter
Stars: ✭ 17 (+0%)
Mutual labels:  tap
nitox
Tokio-based async NATS client
Stars: ✭ 60 (+252.94%)
Mutual labels:  tokio
cargo-trim
Binary application to clean up .cargo/registry & .cargo/git cache
Stars: ✭ 15 (-11.76%)
Mutual labels:  crates
minreq
Simple, minimal-dependency HTTP client.
Stars: ✭ 91 (+435.29%)
Mutual labels:  crates
profext
👣 Profile Extension - A profile 🔎 search engine for accessing my all social media profile in one tap.👨‍💻👩‍. This chrome extension let's you track your profiles on any account in a single click.
Stars: ✭ 43 (+152.94%)
Mutual labels:  tap
crates-io-cn
Source code of crates-io.cn, also tools sets for sync crates.io
Stars: ✭ 20 (+17.65%)
Mutual labels:  crates
hyper-reverse-proxy
A simple reverse proxy for use with Hyper and Tokio
Stars: ✭ 94 (+452.94%)
Mutual labels:  tokio
puppet-homebrew
homebrew (+brewcask! +taps!) package installer and provider
Stars: ✭ 17 (+0%)
Mutual labels:  tap
salak.rs
A multi layered configuration loader and zero-boilerplate configuration parser.
Stars: ✭ 27 (+58.82%)
Mutual labels:  crates
mirdb
MirDB: A Persistent Key-Value Store with Memcached protocol.
Stars: ✭ 75 (+341.18%)
Mutual labels:  tokio

Tokio TUN/TAP

Build crates.io Documentation examples

Asynchronous allocation of TUN/TAP devices in Rust using tokio. Use async-tun for async-std version.

Getting Started

  • Create a tun device using TunBuilder and read from it in a loop:
#[tokio::main]
async fn main() -> Result<()> {
    let tun = TunBuilder::new()
        .name("")            // if name is empty, then it is set by kernel.
        .tap(false)          // false (default): TUN, true: TAP.
        .packet_info(false)  // false: IFF_NO_PI, default is true.
        .up()                // or set it up manually using `sudo ip link set <tun-name> up`.
        .try_build()?;       // or `.try_build_mq(queues)` for multi-queue support.

    println!("tun created, name: {}, fd: {}", tun.name(), tun.as_raw_fd());

    let (mut reader, mut _writer) = tokio::io::split(tun);

    let mut buf = [0u8; 1024];
    loop {
        let n = reader.read(&mut buf).await?;
        println!("reading {} bytes: {:?}", n, &buf[..n]);
    }
}
  • Run the code using sudo:
➜  sudo -E /path/to/cargo run
  • Set the address of device (address and netmask could also be set using TunBuilder):
➜  sudo ip a add 10.0.0.1/24 dev <tun-name>
  • Ping to read packets:
➜  ping 10.0.0.2
  • Display devices and analyze the network traffic:
➜  ip tuntap
➜  sudo tshark -i <tun-name>

Supported Platforms

  • Linux
  • FreeBSD
  • Android
  • OSX
  • iOS
  • Windows

Examples

  • read: Split tun to (reader, writer) pair and read packets from reader.
  • read-mq: Read from multi-queue tun using tokio::select!.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].