Skip to main content

systemconfiguration/
captive_network.rs

1use crate::{bridge, error::Result, ffi};
2
3#[derive(Clone, Copy, Debug, Default)]
4/// Wraps the CaptiveNetwork support APIs in SystemConfiguration.
5pub struct CaptiveNetwork;
6
7impl CaptiveNetwork {
8    /// Wraps `SCCaptiveNetworkCopySupportedInterfaces`.
9    pub fn supported_interfaces() -> Vec<String> {
10        bridge::take_string_array(unsafe {
11            ffi::captive_network::sc_captive_network_copy_supported_interfaces()
12        })
13    }
14
15    /// Wraps `SCCaptiveNetworkSetSupportedSSIDs`.
16    pub fn set_supported_ssids<S: AsRef<str>>(values: &[S]) -> Result<()> {
17        let values = bridge::CStringArray::new(values, "sc_captive_network_set_supported_ssids")?;
18        let ok = unsafe {
19            ffi::captive_network::sc_captive_network_set_supported_ssids(
20                values.as_ptr(),
21                values.count(),
22            )
23        };
24        bridge::bool_result("sc_captive_network_set_supported_ssids", ok)
25    }
26
27    /// Wraps `SCCaptiveNetworkMarkPortalOnline`.
28    pub fn mark_portal_online(interface_name: &str) -> Result<()> {
29        let interface_name =
30            bridge::cstring(interface_name, "sc_captive_network_mark_portal_online")?;
31        let ok = unsafe {
32            ffi::captive_network::sc_captive_network_mark_portal_online(interface_name.as_ptr())
33        };
34        bridge::bool_result("sc_captive_network_mark_portal_online", ok)
35    }
36
37    /// Wraps `SCCaptiveNetworkMarkPortalOffline`.
38    pub fn mark_portal_offline(interface_name: &str) -> Result<()> {
39        let interface_name =
40            bridge::cstring(interface_name, "sc_captive_network_mark_portal_offline")?;
41        let ok = unsafe {
42            ffi::captive_network::sc_captive_network_mark_portal_offline(interface_name.as_ptr())
43        };
44        bridge::bool_result("sc_captive_network_mark_portal_offline", ok)
45    }
46}