vmnet

Docs.rs

Apple's vmnet.framework bindings for Rust.

Installation

Add this to your Cargo.toml:

toml [dependencies] vmnet = "0.1.0"

Usage

Ensure that your software either has an com.apple.vm.networking entitlement or is running with elevated privileges.

Start a NAT interface and receive some packets destined to it:

```rust let sharedmode = Shared { subnetoptions: None, ..Default::default() };

let mut iface = Interface::new(Mode::Shared(shared_mode), Options::default()).unwrap();

let (tx, rx) = sync::mpsc::sync_channel(0);

iface.seteventcallback(Events::PACKETS_AVAILABLE, move |events, params| { if let Some(Parameter::EstimatedPacketsAvailable(pkts)) = params.get(ParameterKind::EstimatedPacketsAvailable) { tx.send(pkts); } }).unwrap();

let pkts = rx.recv().unwrap(); println!("receiving {} packets...", pkts); for _ in 0..pkts { let mut buf: [u8; 1514] = [0; 1514]; println!("{:?}", iface.read(&mut buf)); }

drop(rx); iface.finalize().unwrap(); ```

Quirks and missing functionality