use std::io::Read;
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
let mut config = tun::Configuration::default();
config
.tun_name("utun0")
.address((10, 0, 0, 9))
.netmask((255, 255, 255, 0))
.destination((10, 0, 0, 1))
.up();
#[cfg(target_os = "linux")]
config.platform_config(|config| {
// requiring root privilege to acquire complete functions
config.ensure_root_privileges(true);
});
println!("before tun created");
let mut dev = tun::create(&config)?;
println!("tun created");
let mut buf = [0; 4096];
loop {
let amount = dev.read(&mut buf)?;
println!("{:?}", &buf[0..amount]);
}
}
When set tun name, tun will raise
Error: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })