Skip to main content

arcbox_vmnet/
lib.rs

1//! Safe Rust bindings for Apple's vmnet.framework.
2//!
3//! This crate exposes:
4//! - Low-level FFI declarations for `vmnet`, Core Foundation, GCD dispatch,
5//!   XPC, and the Objective-C block ABI required by `vmnet_start_interface`.
6//! - A high-level [`Vmnet`] interface for creating shared (NAT), host-only,
7//!   and bridged virtual network interfaces.
8//! - A [`VmnetRelay`] that bridges vmnet to a `socketpair` consumed by
9//!   `VZFileHandleNetworkDeviceAttachment`: reads are event-driven via
10//!   `vmnet_interface_set_event_callback`, writes are async on the fd.
11//!
12//! # Operating modes
13//!
14//! - **Shared (NAT)** — VMs share the host's network connection via NAT,
15//!   with vmnet providing DHCP and DNS.
16//! - **Host-only** — Isolated network between VMs and host, optionally
17//!   with per-interface isolation via UUID.
18//! - **Bridged** — VMs appear as separate L2 devices on a physical network.
19//!
20//! # Requirements
21//!
22//! - macOS 11.0 or later.
23//! - The `com.apple.vm.networking` entitlement, or root, is required to
24//!   start a vmnet interface.
25//!
26//! # Feature flags
27//!
28//! - `vmnet` — Enable the proper Objective-C completion-handler ABI for
29//!   `vmnet_start_interface`. Without it, the interface starts with a
30//!   NULL handler and falls back to default packet-size / generated MAC.
31
32#![cfg(target_os = "macos")]
33
34pub mod error;
35pub mod ffi;
36mod interface;
37mod relay;
38
39pub use error::{Result, VmnetError};
40pub use interface::{Vmnet, VmnetConfig, VmnetInterfaceInfo, VmnetMode};
41pub use relay::VmnetRelay;