@@ -16,9 +16,9 @@ use core_foundation::array::CFArray;
16
16
use core_foundation:: base:: { CFType , TCFType } ;
17
17
use core_foundation:: base:: kCFAllocatorDefault;
18
18
use core_foundation:: dictionary:: CFDictionary ;
19
- use core_foundation:: string:: { CFString } ;
19
+ use core_foundation:: string:: CFString ;
20
20
21
- use dynamic_store:: { SCDynamicStore } ;
21
+ use dynamic_store:: SCDynamicStore ;
22
22
pub use system_configuration_sys:: network_configuration:: * ;
23
23
use system_configuration_sys:: preferences:: SCPreferencesCreate ;
24
24
@@ -59,7 +59,6 @@ pub struct DnsSetting {
59
59
60
60
fn global_query ( store : & SCDynamicStore , key : & str ) -> Option < String > {
61
61
let path = CFString :: from_static_string ( "State:/Network/Global/IPv4" ) ;
62
-
63
62
if let Some ( value) = store. get ( path. clone ( ) ) {
64
63
if let Some ( dict) = value. downcast_into :: < CFDictionary > ( ) {
65
64
if let Some ( val) = dict. find2 ( & CFString :: new ( key) ) {
@@ -77,7 +76,6 @@ fn global_query(store: &SCDynamicStore, key: &str) -> Option<String> {
77
76
78
77
/// Returns default route on primary network service.
79
78
pub fn global_router ( store : & SCDynamicStore ) -> Option < IpAddr > {
80
- // let store = SCDynamicStoreBuilder::new(session_name).build();
81
79
if let Some ( router_str) = global_query ( store, "Router" ) {
82
80
if let Ok ( router_ip) = router_str. parse :: < IpAddr > ( ) {
83
81
return Some ( router_ip) ;
@@ -103,7 +101,6 @@ impl_TCFType!(
103
101
impl SCNetworkService {
104
102
/// Returns primary network service
105
103
pub fn global ( store : & SCDynamicStore ) -> Option < Self > {
106
- // let store = SCDynamicStoreBuilder::new(session_name).build();
107
104
if let Some ( service_id) = global_query ( store, "PrimaryService" ) {
108
105
for service in SCNetworkService :: list ( ) {
109
106
if service. id ( ) == service_id {
@@ -128,9 +125,10 @@ impl SCNetworkService {
128
125
let array: CFArray < CFType > =
129
126
unsafe { CFArray :: wrap_under_get_rule ( SCNetworkServiceCopyAll ( prefs) ) } ;
130
127
131
- array. iter ( )
132
- . map ( |item| item. downcast :: < SCNetworkService > ( ) . unwrap ( ) )
133
- . collect :: < Vec < SCNetworkService > > ( )
128
+ array
129
+ . iter ( )
130
+ . map ( |item| item. downcast :: < SCNetworkService > ( ) . unwrap ( ) )
131
+ . collect :: < Vec < SCNetworkService > > ( )
134
132
}
135
133
136
134
/// Returns the user-specified ordering of network services within the specified set.
@@ -152,7 +150,12 @@ impl SCNetworkService {
152
150
153
151
for item in array. iter ( ) {
154
152
if let Some ( id) = item. downcast :: < CFString > ( ) {
155
- let service_ref = unsafe { CFType :: wrap_under_get_rule ( SCNetworkServiceCopy ( prefs, id. as_concrete_TypeRef ( ) ) ) } ;
153
+ let service_ref = unsafe {
154
+ CFType :: wrap_under_get_rule ( SCNetworkServiceCopy (
155
+ prefs,
156
+ id. as_concrete_TypeRef ( ) ,
157
+ ) )
158
+ } ;
156
159
if let Some ( serv) = service_ref. downcast :: < SCNetworkService > ( ) {
157
160
services. push ( serv) ;
158
161
}
@@ -180,7 +183,6 @@ impl SCNetworkService {
180
183
181
184
/// Returns the DNS infomation on this network service
182
185
pub fn dns ( & self , store : & SCDynamicStore ) -> SCNetworkServiceDns {
183
-
184
186
let query = |path : String | -> DnsSetting {
185
187
let mut dns_domain_name: Option < String > = None ;
186
188
let mut dns_server_addresses: Option < Vec < IpAddr > > = None ;
@@ -224,17 +226,15 @@ impl SCNetworkService {
224
226
}
225
227
} ;
226
228
227
- let state_dns_setting =
228
- query ( format ! ( "State:/Network/Service/{}/DNS" , self . id( ) ) ) ;
229
- let setup_dns_setting =
230
- query ( format ! ( "Setup:/Network/Service/{}/DNS" , self . id( ) ) ) ;
229
+ let state_dns_setting = query ( format ! ( "State:/Network/Service/{}/DNS" , self . id( ) ) ) ;
230
+ let setup_dns_setting = query ( format ! ( "Setup:/Network/Service/{}/DNS" , self . id( ) ) ) ;
231
231
232
232
SCNetworkServiceDns {
233
233
state : state_dns_setting,
234
- setup : setup_dns_setting
234
+ setup : setup_dns_setting,
235
235
}
236
236
}
237
-
237
+
238
238
/// Setting DNS Domain Name on this network service
239
239
pub fn set_dns_domain_name ( & self , store : & SCDynamicStore , domain_name : Option < String > ) -> bool {
240
240
let key = CFString :: from_static_string ( "DomainName" ) ;
@@ -247,11 +247,18 @@ impl SCNetworkService {
247
247
}
248
248
249
249
/// Setting DNS Server Addresses on this network service
250
- pub fn set_dns_server_addresses ( & self , store : & SCDynamicStore , server_addrs : Option < Vec < IpAddr > > ) -> bool {
250
+ pub fn set_dns_server_addresses (
251
+ & self ,
252
+ store : & SCDynamicStore ,
253
+ server_addrs : Option < Vec < IpAddr > > ,
254
+ ) -> bool {
251
255
let key = CFString :: from_static_string ( "ServerAddresses" ) ;
252
256
let addrs: Vec < CFString > = match server_addrs {
253
- Some ( addrs) => addrs. iter ( ) . map ( |s| CFString :: new ( & format ! ( "{}" , s) ) ) . collect ( ) ,
254
- None => vec ! [ CFString :: new( "Empty" ) ]
257
+ Some ( addrs) => addrs
258
+ . iter ( )
259
+ . map ( |s| CFString :: new ( & format ! ( "{}" , s) ) )
260
+ . collect ( ) ,
261
+ None => vec ! [ CFString :: new( "Empty" ) ] ,
255
262
} ;
256
263
let value = CFArray :: from_CFTypes ( & addrs) ;
257
264
let dictionary = CFDictionary :: from_CFType_pairs ( & [ ( key, value) ] ) ;
@@ -263,7 +270,8 @@ impl SCNetworkService {
263
270
264
271
/// Returns the network interface associated with this network service.
265
272
pub fn interface ( & self ) -> Option < SCNetworkInterface > {
266
- let interface_ref = unsafe { CFType :: wrap_under_get_rule ( SCNetworkServiceGetInterface ( self . 0 ) ) } ;
273
+ let interface_ref =
274
+ unsafe { CFType :: wrap_under_get_rule ( SCNetworkServiceGetInterface ( self . 0 ) ) } ;
267
275
interface_ref. downcast :: < SCNetworkInterface > ( )
268
276
}
269
277
}
@@ -306,9 +314,10 @@ impl SCNetworkInterface {
306
314
let array: CFArray < CFType > =
307
315
unsafe { CFArray :: wrap_under_get_rule ( SCNetworkInterfaceCopyAll ( ) ) } ;
308
316
309
- array. iter ( )
310
- . map ( |item| item. downcast :: < SCNetworkInterface > ( ) . unwrap ( ) )
311
- . collect :: < Vec < SCNetworkInterface > > ( )
317
+ array
318
+ . iter ( )
319
+ . map ( |item| item. downcast :: < SCNetworkInterface > ( ) . unwrap ( ) )
320
+ . collect :: < Vec < SCNetworkInterface > > ( )
312
321
}
313
322
314
323
/// Returns the current MTU setting and the range of allowable values
0 commit comments