Skip to main content

09_network_protocol/
09_network_protocol.rs

1use systemconfiguration::{NetworkService, Preferences};
2
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let prefs = Preferences::new("systemconfiguration-rs.network-protocol-example", None)?;
5    if let Some(protocol) = NetworkService::copy_all(&prefs)
6        .into_iter()
7        .flat_map(|service| service.copy_protocols())
8        .next()
9    {
10        println!(
11            "protocol_type={:?} enabled={} has_config={}",
12            protocol.protocol_type(),
13            protocol.is_enabled(),
14            protocol.configuration().is_some()
15        );
16    } else {
17        println!("no network protocols available");
18    }
19    Ok(())
20}