wireguard-nt
Safe rust idiomatic bindings for the WireGuard NT C library: https://git.zx2c4.com/wireguard-nt/about
Features of the WireGuard NT library are wrapped using pure rust types and functions to make usage ergonomic.
Usage
Add a dependency on this library to your Cargo.toml
[]
= "0.4"
Inside your code load the wireguard.dll signed driver file, downloaded from https://git.zx2c4.com/wireguard-nt/about
Then either call [Adapter::create
] or [Adapter::open
] to obtain a wireguard
adapter. Start by setting its config with [Adapter::set_config
].
Example
//Must be run as Administrator because we create network adapters
//Load the wireguard dll file so that we can call the underlying C functions
//Unsafe because we are loading an arbitrary dll file
let wireguard = unsafe .expect;
//Try to open an adapter with the name "Demo"
let adapter = match open ;
let interface = SetInterface ;
//Set the config our adapter will use
//This lets it know about the peers and keys
adapter.set_config.unwrap;
let internal_ip = "10.4.0.2".parse.unwrap;
let internal_prefix_length = 24;
let internal_ipnet = new.unwrap;
//Set up the routing table with the allowed ips for our peers,
//and assign an ip to the interface
adapter.set_default_route.unwrap;
//drop(adapter)
//The adapter closes its resources when dropped
See examples/demo_server.rs
that connects to the wireguard demo server
Version compatibility
Wireguard NT versions 0.10 and above are supported. Versions < 0.10 have breaking changes that make interoperability hard. Please file an issue if this effects your use case.
License: MIT