Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
luozijun committed Feb 28, 2018
1 parent b02a297 commit 563646b
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 153 deletions.
6 changes: 3 additions & 3 deletions system-configuration/examples/network_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use system_configuration::network_configuration::{global_router, SCNetworkInterf
fn main() {
let store = SCDynamicStoreBuilder::new("session_name").build();


println!("Global Service:\n{:?}\n", SCNetworkService::global(&store));
let service = SCNetworkService::global(&store).unwrap();
println!("Global Service:\n{:?}\n", service);
println!(
"Global Interface:\n{:?}\n",
SCNetworkInterface::global(&store)
service.interface()
);
println!("Global Service Router:\n{:?}\n", global_router(&store));

Expand Down
19 changes: 10 additions & 9 deletions system-configuration/examples/set_dns.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extern crate system_configuration;

use system_configuration::network_configuration::{SCNetworkGlobal, SCNetworkServiceDns};
use system_configuration::dynamic_store::SCDynamicStoreBuilder;
use system_configuration::network_configuration::{SCNetworkService};

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

Expand All @@ -18,16 +19,16 @@ fn main() {
IpAddr::V4(Ipv4Addr::new(8, 8, 4, 4)),
];

let global_service = SCNetworkGlobal.service().expect("No PrimaryService active");
let global_interface = global_service
.interface()
.expect("No PrimaryInterface active");
let store = SCDynamicStoreBuilder::new("session_name").build();

let global_service = SCNetworkService::global(&store).expect("No PrimaryService active");
let global_interface = global_service.interface().expect("No PrimaryInterface active");

println!("Global Service:");
println!("\tid: {:?}", global_service.id());
println!("\tname: {:?}", global_service.name());
println!("\tenabled: {:?}", global_service.enabled());
println!("\tdns: {:?}", global_service.dns());
println!("\tdns: {:?}", global_service.dns(&store));
println!("\tinterface: {:?}", global_interface.name().unwrap());

println!(
Expand All @@ -36,15 +37,15 @@ fn main() {
global_service.name()
);

let dns = SCNetworkServiceDns::new((None, None), (None, Some(addrs)));
// let dns = SCNetworkServiceDns::new((None, None), (None, Some(addrs)));

println!("Success: {:?}", global_service.set_dns(dns));
println!("Success: {:?}", global_service.set_dns_server_addresses(&store, Some(addrs) ));

// Check
// networksetup -getdnsservers "Wi-Fi"
// scutil --dns
// dig
println!("{:?}", global_service.dns());
println!("{:?}", global_service.dns(&store));

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

0 comments on commit 563646b

Please sign in to comment.