netmap-min-sys
This crate provides low-level FFI (Foreign Function Interface) bindings to the Netmap C library. Netmap is a framework for very fast packet I/O from userspace.
netmap-min-sys is a "sys" crate: it handles C header parsing, library
linking and exposes raw, unsafe bindings. Higher-level, safe abstractions are
provided by the netmap-rs crate, which depends on this one.
What is exposed
- bindgen-generated bindings for the
netmap_*,nmreq_*andNR_*/NS_*/NETMAP_*families from<net/netmap.h>and<net/netmap_user.h>. nm_open/nm_close/nm_mmap/nm_inject— the standard Netmap descriptor helpers. These arestaticfunctions insidenetmap_user.h, so no shared library exports them; this crate compiles them in through a small C shim (c/netmap_shim.c), so you only need the Netmap headers, not a builtlibnetmap.NETMAP_TXRING/NETMAP_RXRING/NETMAP_IF/NETMAP_BUF— safe-ish Rust functions implementing the offset macros fromnetmap_user.h.- ioctl numbers
NIOCRXSYNC,NIOCTXSYNC,NIOCREGIF,NIOCCTRL, which bindgen cannot expand from the_IO/_IOWRmacros.
Prerequisites
To compile and use this crate (and, by extension, netmap-rs with its sys
feature), you must have the Netmap C headers installed on your system.
- Install the Netmap headers: clone the
netmap repository,
cd sys, then copy thenet/headers into an include directory (seenetmap-rs/scripts/install_netmap.shfor a complete example). - Install Clang: the
bindgentool used by this crate's build script to generate Rust bindings from C headers requiresclang. (e.g.sudo apt install clang libclang-devon Debian/Ubuntu).
Build Configuration
The build script (build.rs) locates your Netmap installation through the
NETMAP_LOCATION environment variable (defaulting to /usr/local).
Standard Installation
If the Netmap headers are installed in a standard location (e.g.
/usr/local/include/net/netmap.h), the build script finds them automatically.
Custom Netmap Installation Path (NETMAP_LOCATION)
Set NETMAP_LOCATION to the root directory that contains the include and
lib subdirectories.
NETMAP_LOCATION=/opt/netmap
The build script then:
- instructs
bindgento look for headers in$NETMAP_LOCATION/include; - passes
$NETMAP_LOCATION/libto the linker; - exposes
NETMAP_INCLUDE_PATHandNETMAP_LIB_PATHascargo:rustc-envvalues so downstream crates can reuse them.
Disabling Netmap (disable-netmap-kernel)
On platforms where Netmap is unavailable, build the crate as a no-op with the
disable-netmap-kernel feature or the DISABLE_NETMAP_KERNEL environment
variable. The build script skips bindgen and the C shim, and the crate
exports an empty API.
# or
DISABLE_NETMAP_KERNEL=1
Usage
This crate is not typically used directly. The netmap-rs crate provides safe
Rust abstractions over the raw bindings exposed here. If you are using
netmap-rs, enable its sys feature, which pulls in and configures this
-sys crate.
License
- Apache License, Version 2.0, (LICENSE-APACHE).
- MIT license (LICENSE-MIT).