Using tun_tap_mac crate on MacOS

903 views Asked by At

I'm trying to use the tun_tap_mac crate on MacOS and I'm having trouble with getting started. Here's my code:

fn main() -> io::Result<()> {
    let nic = tun_tap_mac::Iface::new("tun0", tun_tap_mac::Mode::Tun)
        .expect("Failed to create TUN device");

    let mut buf = vec![0u8; 1504];
    let nbytes = nic.recv(&mut buf[..])?;

    println!("read {:?} bytes: {:?}", nbytes, &buf[..nbytes]);

    Ok(())
}

and I'm getting this error:

thread 'main' panicked at 'Failed to create TUN device: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/main.rs:5:10

I've tried building with sudo and I'm getting the same problems. MacOS doesn't have a setcap-like ability and the documentation seems very sparse. It looks like this crate is forked from the original tun_tap to support Mac but I can't really find any other help. Any advice?

1

There are 1 answers

0
avi On

I ran into the error as well. This error occurs when then TUN/TAP drivers are not installed on OS X, which you can install from here, however it is no longer maintained and its a hit or miss to get it working on OS X.

I would suggest using another crate rust-tun which just works out of the box and uses utun driver which is present in OS X by default.