Skip to content
shellrowPublic

About

Cross-platform library for network interface. Written in Rust.

Topics

Resources

Stars

107 stars

Watchers

3 watching

Forks

Latest commit

 

History

556 Commits

Folders and files

Repository files navigation

netdev Crates.io License

Cross-platform library for enumerating network interfaces with metadata.
netdev provides a unified API for discovering local network interfaces and retrieving commonly used metadata across platforms.

Key Features

  • Enumerate all available network interfaces
  • Detect the default network interface
  • Retrieve interface metadata:
    • Interface type
    • MAC address
    • IPv4 / IPv6 addresses and prefixes
    • MTU, flags, operational state, etc...
  • Native traffic statistics (RX/TX bytes) for each interface
  • Designed for cross-platform

See the Interface struct documentation for more details.

Supported platforms

  • Linux
  • macOS
  • Windows
  • Android
  • iOS
  • BSDs

Usage

Add netdev to your Cargo.toml:

[dependencies]
netdev = "0.48"

Cargo features

Feature Default Effect
gateway Yes Adds default-interface and gateway lookups, gateway addresses, and DNS servers.
android-extra Yes Uses Android APIs through JNI for additional traffic, DNS, DHCP, and Wi-Fi metadata.
apple-system-configuration-extra Yes Enables additional macOS SystemConfiguration bindings. Interface metadata collection also works with this feature disabled.
apple-wifi-extra No Reads macOS Wi-Fi transmit speed through CoreWLAN. This can perform synchronous IPC during enumeration.
serde No Enables serialization and deserialization of interface data.

For more details, see examples or doc.

Platform notes

  • Linux uses routes and destination rules to choose a UDP lookup destination outside more-specific prefixes when possible. The kernel selects the route. When the table is unavailable, it uses a fixed destination, as do several other platforms. A split VPN can affect that fallback.
  • On Android, the host must initialize ndk-context before the first interface or traffic-counter lookup with android-extra. Some Android runtimes do this during startup. A missing context aborts the process in builds using panic = "abort". Android network and Wi-Fi metadata also depend on app permissions such as ACCESS_NETWORK_STATE and ACCESS_WIFI_STATE. For standalone binaries without an Android context, use default-features = false and enable gateway as needed.
  • On macOS, Xcode targets that perform the final link may need to link SystemConfiguration.framework. On macOS and iOS, the native byte counters wrap at 4 GiB.
  • On illumos, traffic counters, gateway addresses, and DNS servers are unavailable. The default-interface helper can still identify the interface by its source address.

Project History

This crate was originally published as default-net and was later rebranded to netdev by the author for future expansion, clearer naming, and long-term maintenance.

About

Cross-platform library for network interface. Written in Rust.

Topics

Resources

Stars

107 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages