Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ objc2-system-configuration = { version = "0.3", default-features = false, featur
plist = "1.8"

[target.'cfg(target_os = "macos")'.dependencies]
objc2 = { version = "0.6" }
objc2-core-wlan = { version = "0.3" }
objc2-foundation = { version = "0.3" }
objc2 = { version = "0.6", optional = true }
objc2-core-wlan = { version = "0.3", optional = true }
objc2-foundation = { version = "0.3", optional = true }

[target.'cfg(target_os = "ios")'.dependencies]
dispatch2 = "0.3"
Expand All @@ -60,6 +60,7 @@ default = ["gateway", "apple-system-configuration-extra", "android-extra"]
serde = ["dep:serde", "mac-addr/serde", "ipnet/serde"]
gateway = []
android-extra = ["dep:jni", "dep:ndk-context"]
apple-wifi-extra = ["dep:objc2", "dep:objc2-core-wlan", "dep:objc2-foundation"]
apple-system-configuration-extra = [
"objc2-system-configuration/SCPreferences",
"objc2-system-configuration/SCDynamicStore",
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ For more details, see [examples][examples-url] or [doc][doc-url].
- `android-extra` (default)
- Enables deeper Android metadata enrichment using Android platform APIs through JNI bindings.
- On Android, this can add metadata such as traffic stats, DNS servers, DHCP hints, and Wi-Fi link speed when the app provides the required Android context and permissions.
- `apple-wifi-extra`
- Enables macOS Wi-Fi transmit-speed collection through CoreWLAN.
- This feature is disabled by default because CoreWLAN metadata collection may perform synchronous IPC during interface enumeration.

To opt out of the additional Apple metadata enrichment while keeping gateway helpers:

Expand All @@ -65,6 +68,17 @@ netdev = { version = "0.45", default-features = false, features = ["gateway"] }
`netdev` links `SystemConfiguration.framework` automatically on `macOS` and `iOS` through its build script.
If your app is ultimately linked by Xcode, you may still need to add `SystemConfiguration.framework` to the app target manually.

macOS Wi-Fi transmit-speed collection is disabled by default. To enable it, opt in to the
`apple-wifi-extra` feature:

```toml
[dependencies]
netdev = { version = "0.45", features = ["apple-wifi-extra"] }
```

This uses CoreWLAN, whose metadata lookup may perform synchronous IPC while interfaces are
being enumerated.

## Android behavior
If you want Android-specific values such as DNS servers, DHCP hints, or Wi-Fi link speed, your app may still need to initialize the Android context for Rust and declare Android permissions such as `ACCESS_NETWORK_STATE` and `ACCESS_WIFI_STATE`.

Expand Down
3 changes: 3 additions & 0 deletions src/interface/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ pub struct Interface {
/// This field is usually available on Linux, Android, BSD, Apple targets, and Windows.
/// It may be `None` for virtual adapters, unsupported drivers, or platforms that do not
/// expose link speed.
///
/// On macOS, collecting Wi-Fi transmit speed through CoreWLAN requires the
/// `apple-wifi-extra` feature, which is disabled by default.
pub transmit_speed: Option<u64>,
/// Reported receive link speed in bits per second.
///
Expand Down
10 changes: 5 additions & 5 deletions src/os/macos/interface.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::os::darwin::types::{get_functional_type, interface_type_by_name};
use crate::os::macos::sc::{get_sc_interface_map, read_sc_plist_interface_map};
#[cfg(feature = "apple-wifi-extra")]
use crate::os::macos::wifi::get_wifi_transmit_rate;
use crate::{
interface::interface::Interface,
os::{
macos::sc::SCInterface, macos::wifi::get_wifi_transmit_rate,
unix::interface::unix_interfaces,
},
os::{macos::sc::SCInterface, unix::interface::unix_interfaces},
prelude::InterfaceType,
};

Expand Down Expand Up @@ -44,7 +43,8 @@ pub fn interfaces() -> Vec<Interface> {
iface.dhcp_v6_enabled = sc_inface.dhcp_v6_enabled;
}

if iface.if_type == InterfaceType::Wireless80211 {
#[cfg(feature = "apple-wifi-extra")]
if iface.if_type == InterfaceType::Wireless80211 && iface.is_up() {
iface.transmit_speed = get_wifi_transmit_rate(&iface.name);
}

Expand Down
1 change: 1 addition & 0 deletions src/os/macos/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod interface;
pub mod sc;

#[cfg(feature = "apple-wifi-extra")]
mod wifi;
Loading