Skip to content

Commit d57eef8

Browse files
author
luozijun
committed
Update
1 parent b02a297 commit d57eef8

File tree

3 files changed

+91
-154
lines changed

3 files changed

+91
-154
lines changed

system-configuration/examples/network_configuration.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use system_configuration::network_configuration::{global_router, SCNetworkInterf
1010
fn main() {
1111
let store = SCDynamicStoreBuilder::new("session_name").build();
1212

13-
14-
println!("Global Service:\n{:?}\n", SCNetworkService::global(&store));
13+
let service = SCNetworkService::global(&store).unwrap();
14+
println!("Global Service:\n{:?}\n", service);
1515
println!(
1616
"Global Interface:\n{:?}\n",
17-
SCNetworkInterface::global(&store)
17+
service.interface()
1818
);
1919
println!("Global Service Router:\n{:?}\n", global_router(&store));
2020

system-configuration/examples/set_dns.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
extern crate system_configuration;
22

3-
use system_configuration::network_configuration::{SCNetworkGlobal, SCNetworkServiceDns};
3+
use system_configuration::dynamic_store::SCDynamicStoreBuilder;
4+
use system_configuration::network_configuration::{SCNetworkService};
45

56
use std::net::{IpAddr, Ipv4Addr};
67

@@ -18,33 +19,32 @@ fn main() {
1819
IpAddr::V4(Ipv4Addr::new(8, 8, 4, 4)),
1920
];
2021

21-
let global_service = SCNetworkGlobal.service().expect("No PrimaryService active");
22-
let global_interface = global_service
23-
.interface()
24-
.expect("No PrimaryInterface active");
22+
let store = SCDynamicStoreBuilder::new("session_name").build();
23+
24+
let global_service = SCNetworkService::global(&store).expect("No PrimaryService active");
25+
let global_interface = global_service.interface().expect("No PrimaryInterface active");
2526

2627
println!("Global Service:");
2728
println!("\tid: {:?}", global_service.id());
2829
println!("\tname: {:?}", global_service.name());
2930
println!("\tenabled: {:?}", global_service.enabled());
30-
println!("\tdns: {:?}", global_service.dns());
31+
println!("\tdns: {:?}", global_service.dns(&store));
3132
println!("\tinterface: {:?}", global_interface.name().unwrap());
3233

3334
println!(
3435
"Set dns to {:?} on {:?} service ...",
3536
addrs,
3637
global_service.name()
3738
);
39+
3840

39-
let dns = SCNetworkServiceDns::new((None, None), (None, Some(addrs)));
40-
41-
println!("Success: {:?}", global_service.set_dns(dns));
41+
println!("Success: {:?}", global_service.set_dns_server_addresses(&store, Some(addrs) ));
4242

4343
// Check
4444
// networksetup -getdnsservers "Wi-Fi"
4545
// scutil --dns
4646
// dig
47-
println!("{:?}", global_service.dns());
47+
println!("{:?}", global_service.dns(&store));
4848

4949
println!(
5050
"\n\nUse Command `networksetup -setdnsservers \"{}\" \"Empty\"` to restore DNS setting. ",

0 commit comments

Comments
 (0)