Skip to main content

systemconfiguration/
network_configuration.rs

1use std::collections::BTreeMap;
2
3use serde::Deserialize;
4
5use crate::{bridge, error::Result, ffi};
6
7#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
8/// Wraps a summary built from SystemConfiguration network-configuration APIs.
9pub struct NetworkConfigurationOverview {
10    /// Wraps the interface count derived from `SCNetworkInterfaceCopyAll`.
11    pub interface_count: usize,
12    /// Wraps the service count derived from `SCNetworkServiceCopyAll`.
13    pub service_count: usize,
14    /// Wraps the set count derived from `SCNetworkSetCopyAll`.
15    pub set_count: usize,
16    /// Wraps the current set name derived from `SCNetworkSetCopyCurrent`.
17    pub current_set_name: Option<String>,
18    /// Wraps the current set identifier derived from `SCNetworkSetCopyCurrent`.
19    pub current_set_id: Option<String>,
20    /// Wraps interface-type symbols from `SCNetworkInterfaceCopyAll`.
21    pub interface_types: BTreeMap<String, String>,
22    /// Wraps protocol-type symbols from `SCNetworkServiceCopyProtocols`.
23    pub protocol_types: BTreeMap<String, String>,
24}
25
26#[derive(Clone, Copy, Debug, Default)]
27/// Provides overview helpers for SystemConfiguration network-configuration APIs.
28pub struct NetworkConfiguration;
29
30impl NetworkConfiguration {
31    /// Wraps the bridge overview assembled from `SCNetworkInterfaceCopyAll`, `SCNetworkServiceCopyAll`, and `SCNetworkSetCopyAll`.
32    pub fn overview() -> Result<NetworkConfigurationOverview> {
33        bridge::parse_json("sc_network_configuration_copy_overview", unsafe {
34            ffi::network_configuration::sc_network_configuration_copy_overview()
35        })
36    }
37}