12 unstable releases (3 breaking)

0.4.0 Jan 12, 2024
0.3.2 Sep 27, 2023
0.2.1 Dec 3, 2021
0.1.5 Aug 27, 2021
0.1.3 Jun 28, 2021

#130 in Hardware support

Download history 630/week @ 2023-12-23 2037/week @ 2023-12-30 2372/week @ 2024-01-06 3520/week @ 2024-01-13 3488/week @ 2024-01-20 5333/week @ 2024-01-27 2910/week @ 2024-02-03 3748/week @ 2024-02-10 4303/week @ 2024-02-17 3436/week @ 2024-02-24 2886/week @ 2024-03-02 2310/week @ 2024-03-09 2355/week @ 2024-03-16 2161/week @ 2024-03-23 2424/week @ 2024-03-30 2634/week @ 2024-04-06

9,811 downloads per month
Used in 14 crates (5 directly)

MIT license

1.5K SLoC

Contains (Windows DLL, 550KB) wintun/bin/x86/wintun.dll, (Windows DLL, 430KB) wintun/bin/amd64/wintun.dll, (Windows DLL, 365KB) wintun/bin/arm/wintun.dll, (Windows DLL, 225KB) wintun/bin/arm64/wintun.dll


Safe rust idiomatic bindings for the Wintun C library: https://wintun.net

All features of the Wintun library are wrapped using pure rust types and functions to make usage feel ergonomic.

Version Documentation Download License


Inside your code load the wintun.dll signed driver file, downloaded from https://wintun.net, using load, load_from_path or load_from_library.

Then either call Adapter::create or Adapter::open to obtain a wintun adapter. Start a session with Adapter::start_session.


use std::sync::Arc;

//Must be run as Administrator because we create network adapters
//Load the wintun dll file so that we can call the underlying C functions
//Unsafe because we are loading an arbitrary dll file
let wintun = unsafe { wintun::load_from_path("path/to/wintun.dll") }
    .expect("Failed to load wintun dll");

//Try to open an adapter with the name "Demo"
let adapter = match wintun::Adapter::open(&wintun, "Demo") {
    Ok(a) => a,
    Err(_) => {
        //If loading failed (most likely it didn't exist), create a new one
        wintun::Adapter::create(&wintun, "Demo", "Example", None)
            .expect("Failed to create wintun adapter!")
//Specify the size of the ring buffer the wintun driver should use.
let session = Arc::new(adapter.start_session(wintun::MAX_RING_CAPACITY).unwrap());

//Get a 20 byte packet from the ring buffer
let mut packet = session.allocate_send_packet(20).unwrap();
let bytes: &mut [u8] = packet.bytes_mut();
//Write IPV4 version and header length
bytes[0] = 0x40;

//Finish writing IP header
bytes[9] = 0x69;
bytes[10] = 0x04;
bytes[11] = 0x20;

//Send the packet to wintun virtual adapter for processing by the system

//Stop any readers blocking for data on other threads
//Only needed when a blocking reader is preventing shutdown Ie. it holds an Arc to the
//session, blocking it from being dropped

//the session is stopped on drop

//And the adapter closes its resources when dropped

See examples/wireshark.rs for a more complete example that writes received packets to a pcap file.


  • panic_on_unsent_packets: Panics if a send packet is dropped without being sent. Useful for debugging packet issues because unsent packets that are dropped without being sent hold up wintun's internal ring buffer.


  • Add async support Requires hooking into a windows specific reactor and registering read interest on wintun's read handle. Asyncify other slow operations via tokio::spawn_blocking. As always, PR's are welcome!

License: MIT


~2.5M SLoC