Cross-platform low-level networking library in Rust
nex is a Rust library that provides cross-platform low-level networking capabilities.
It includes sub-crates with responsibilities:
nex-packet: Low-level packet parsing and serialization.nex-datalink: Raw datalink send/receive backends across platforms.nex-socket: Low-level socket operations with cross-platform option handling.
The project aims to expose portable low-level primitives.
nex requires Rust 1.88.0 or later. MSRV changes are treated as compatibility
changes and are verified in CI.
To use nex, add it as a dependency in your Cargo.toml:
[dependencies]
nex = "0.28"You can also directly use specific sub-crates by importing them individually.
nex-datalinknex-packetnex-socket
If you want to focus on network interfaces, you can use the netdev.
All optional features are disabled by default in nex, nex-packet,
nex-datalink, and nex-socket. nex-core keeps gateway enabled by default
because gateway discovery is part of its primary interface functionality.
| Feature | Crate | Purpose |
|---|---|---|
async |
nex, nex-datalink, nex-socket |
Enables asynchronous datalink I/O and Tokio-based socket APIs. |
pcap |
nex, nex-datalink |
Enables the libpcap backend. |
winptap |
nex, nex-datalink |
Enables an explicitly selected receive-only Windows Packet Monitor backend without Npcap; combine with async for asynchronous reception. |
serde |
nex, nex-core, nex-packet, nex-datalink |
Enables serialization support for public data types. |
gateway |
nex-core |
Enables default gateway discovery through netdev. |
To use asynchronous APIs through the facade:
[dependencies]
nex = { version = "0.28", features = ["async"] }nex-datalink uses a raw socket which may require elevated privileges depending on your system's configuration.
Execute with administrator privileges if necessary.
For receive-only Ethernet capture without Npcap, enable winptap and call
nex::datalink::winptap::open with its dedicated configuration. This requires
administrator privileges and does not support transmission or promiscuous mode.
With both winptap and async, winptap::open_async returns a runtime-independent
AsyncRawReceiver/Stream with a bounded handoff and cross-thread cancellation.
The official backend observes incoming and outgoing traffic; native observes
incoming traffic only.
Please note that in order to send and receive raw packets using nex-datalink on Windows, Npcap is required.
-
Install Npcap, making sure to check Install Npcap in WinPcap API-compatible Mode during the installation.
-
The default datalink backend loads Npcap at runtime and does not require the Npcap SDK to build. If you enable the optional
pcapfeature, download the Npcap SDK and add itsLib/x64(orLibfor 32-bit builds) folder to yourLIBenvironment variable.
On macOS, managing access to the Berkeley Packet Filter (BPF) devices is necessary to send and receive raw packets using nex-datalink.
You can use chmod-bpf to automatically manage permissions for BPF devices.
Alternatively, of course, you can also use sudo to temporarily grant the necessary permissions.