Crates.io | vmnet |
lib.rs | vmnet |
version | 0.3.0 |
source | src |
created_at | 2022-06-08 00:53:08.277576 |
updated_at | 2023-09-23 18:36:47.835392 |
description | Apple's vmnet.framework bindings |
homepage | |
repository | https://github.com/edigaryev/vmnet |
max_upload_size | |
id | 601775 |
size | 38,830 |
Apple's vmnet.framework
bindings for Rust.
Add this to your Cargo.toml
:
[dependencies]
vmnet = "0"
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:
let shared_mode = Shared {
subnet_options: None,
..Default::default()
};
let mut iface = Interface::new(Mode::Shared(shared_mode), Options::default()).unwrap();
let (tx, rx) = sync::mpsc::sync_channel(0);
iface.set_event_callback(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();
set_event_callback()
require the provided closure to have a 'static
lifetime
Interface
from such closureAPI_AVAILABLE
macro not being supported it is assumed that this package is running on macOS 11.0 or newer