|
| 1 | +extern crate system_configuration; |
| 2 | +extern crate system_configuration_sys; |
| 3 | + |
| 4 | +extern crate core_foundation; |
| 5 | +extern crate core_foundation_sys; |
| 6 | + |
| 7 | +use core_foundation::array::CFArray; |
| 8 | +use core_foundation::base::TCFType; |
| 9 | +use core_foundation::dictionary::CFDictionary; |
| 10 | +use core_foundation::string::{CFString, CFStringRef}; |
| 11 | + |
| 12 | +use system_configuration::dynamic_store::SCDynamicStore; |
| 13 | + |
| 14 | +fn main() { |
| 15 | + unsafe { |
| 16 | + let store = SCDynamicStore::create("my-test-dyn-store"); |
| 17 | + println!("Created dynamic store"); |
| 18 | + |
| 19 | + let ipv4_dict = store |
| 20 | + .get("State:/Network/Global/IPv4") |
| 21 | + .expect("Unable to find global settings"); |
| 22 | + println!("Got IPv4 global property list"); |
| 23 | + |
| 24 | + let pri_service_id_ptr = ipv4_dict |
| 25 | + .find2(&CFString::from_static_string("PrimaryService")) |
| 26 | + .expect("No PrimaryService"); |
| 27 | + let pri_service_id = CFString::wrap_under_get_rule(pri_service_id_ptr as CFStringRef); |
| 28 | + |
| 29 | + let pri_service_path = |
| 30 | + CFString::new(&format!("State:/Network/Service/{}/DNS", pri_service_id)); |
| 31 | + println!("PrimaryService path: {}", pri_service_path); |
| 32 | + |
| 33 | + let server_addresses_key = CFString::from_static_string("ServerAddresses"); |
| 34 | + let server_addresses_value = CFArray::from_CFTypes(&[ |
| 35 | + CFString::from_static_string("8.8.8.8"), |
| 36 | + CFString::from_static_string("8.8.4.4"), |
| 37 | + ]); |
| 38 | + let dns_dictionary = |
| 39 | + CFDictionary::from_CFType_pairs(&[(server_addresses_key, server_addresses_value)]); |
| 40 | + |
| 41 | + let success = store.set(pri_service_path, &dns_dictionary); |
| 42 | + println!("success? {}", success); |
| 43 | + } |
| 44 | +} |
0 commit comments