Skip to content

Commit a35a48c

Browse files
author
luozijun
committed
Add High-level API
1 parent 290fc79 commit a35a48c

File tree

7 files changed

+558
-1
lines changed

7 files changed

+558
-1
lines changed

system-configuration-sys/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@
1919
extern crate core_foundation_sys;
2020

2121
pub mod dynamic_store;
22+
23+
mod preferences;
24+
mod network_configuration;
25+
26+
pub use dynamic_store::*;
27+
pub use preferences::*;
28+
pub use network_configuration::*;
29+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use core_foundation_sys::base::Boolean;
2+
use core_foundation_sys::string::CFStringRef;
3+
use core_foundation_sys::dictionary::CFDictionaryRef;
4+
use core_foundation_sys::array::CFArrayRef;
5+
6+
use SCPreferencesRef;
7+
8+
use std::os::raw::{c_void, c_int};
9+
10+
11+
pub type __SCNetworkInterface = c_void;
12+
pub type SCNetworkInterfaceRef = *const __SCNetworkInterface;
13+
pub type SCBondInterfaceRef = SCNetworkInterfaceRef;
14+
pub type SCVLANInterfaceRef = SCNetworkInterfaceRef;
15+
16+
pub type __SCBondStatus = c_void;
17+
pub type SCBondStatusRef = *const __SCBondStatus;
18+
19+
pub type __SCNetworkProtocol = c_void;
20+
pub type SCNetworkProtocolRef = *const __SCNetworkProtocol;
21+
22+
pub type __SCNetworkService = c_void;
23+
pub type SCNetworkServiceRef = *const __SCNetworkService;
24+
25+
pub type __SCNetworkSet = c_void;
26+
pub type SCNetworkSetRef = *const __SCNetworkSet;
27+
28+
29+
#[link(name = "SystemConfiguration", kind = "framework")]
30+
extern "C" {
31+
pub fn SCNetworkServiceCopyAll(prefs: SCPreferencesRef) -> CFArrayRef;
32+
pub fn SCNetworkServiceCopy(prefs: SCPreferencesRef,
33+
serviceID: CFStringRef) -> SCNetworkServiceRef;
34+
pub fn SCNetworkServiceGetEnabled(service: SCNetworkServiceRef) -> Boolean;
35+
pub fn SCNetworkServiceGetInterface(service: SCNetworkServiceRef) -> SCNetworkInterfaceRef;
36+
pub fn SCNetworkServiceGetName(service: SCNetworkServiceRef) -> CFStringRef;
37+
pub fn SCNetworkServiceGetServiceID(service: SCNetworkServiceRef) -> CFStringRef;
38+
pub fn SCNetworkSetGetServiceOrder(set: SCNetworkSetRef) -> CFArrayRef;
39+
pub fn SCNetworkSetCopyServices(set: SCNetworkSetRef) -> CFArrayRef;
40+
pub fn SCNetworkSetCopyCurrent(prefs:SCPreferencesRef) -> SCNetworkSetRef;
41+
42+
pub fn SCNetworkInterfaceCopyAll() -> CFArrayRef;
43+
pub fn SCNetworkInterfaceCopyMTU(interface: SCNetworkInterfaceRef,
44+
mtu_cur: *mut c_int,
45+
mtu_min: *mut c_int,
46+
mtu_max: *mut c_int) -> Boolean;
47+
pub fn SCNetworkInterfaceCopyMediaOptions(interface: SCNetworkInterfaceRef,
48+
urrent: *mut CFDictionaryRef,
49+
active: *mut CFDictionaryRef,
50+
available: *mut CFArrayRef,
51+
filter: Boolean) -> Boolean;
52+
pub fn SCNetworkInterfaceGetBSDName(interface: SCNetworkInterfaceRef) -> CFStringRef;
53+
pub fn SCNetworkInterfaceGetInterfaceType(interface: SCNetworkInterfaceRef) -> CFStringRef;
54+
pub fn SCNetworkInterfaceGetHardwareAddressString(interface: SCNetworkInterfaceRef) -> CFStringRef;
55+
56+
pub fn SCNetworkInterfaceGetConfiguration(interface: SCNetworkInterfaceRef) -> CFDictionaryRef;
57+
pub fn SCNetworkInterfaceGetExtendedConfiguration(interface: SCNetworkInterfaceRef,
58+
extendedType: CFStringRef) -> CFDictionaryRef;
59+
60+
pub fn SCNetworkInterfaceSetConfiguration(interface: SCNetworkInterfaceRef,
61+
config: CFDictionaryRef) -> Boolean;
62+
pub fn SCNetworkInterfaceSetExtendedConfiguration(interface: SCNetworkInterfaceRef,
63+
extendedType: CFStringRef,
64+
config: CFDictionaryRef) -> Boolean;
65+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use core_foundation_sys::base::CFAllocatorRef;
2+
use core_foundation_sys::string::CFStringRef;
3+
4+
use std::os::raw::c_void;
5+
6+
7+
pub type __SCPreferences = c_void;
8+
pub type SCPreferencesRef = *const __SCPreferences;
9+
10+
11+
#[link(name = "SystemConfiguration", kind = "framework")]
12+
extern "C" {
13+
pub fn SCPreferencesCreate(allocator: CFAllocatorRef,
14+
name: CFStringRef,
15+
prefsID: CFStringRef) -> SCPreferencesRef;
16+
}

system-configuration/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ readme = "../README.md"
1111

1212
[dependencies]
1313
core-foundation = "0.5"
14-
14+
core-foundation-sys = "0.5"
1515
system-configuration-sys = { path = "../system-configuration-sys", version = "0.1" }

system-configuration/examples/dns.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
extern crate system_configuration;
2+
3+
use system_configuration::network_configuration::{
4+
// SCNetworkInterfaceMTU, SCNetworkServiceDNS,
5+
SCNetworkGlobal, SCNetworkService, SCNetworkInterface
6+
};
7+
8+
9+
fn main (){
10+
println!("{:?}", SCNetworkGlobal.service());
11+
12+
println!("{:?}", SCNetworkGlobal.interface());
13+
14+
println!("{:?}", SCNetworkGlobal.router());
15+
16+
for service in SCNetworkService::list_order() {
17+
println!("{:?}\n\n", service);
18+
}
19+
20+
for service in SCNetworkService::list() {
21+
println!("{:?}\n\n", service);
22+
}
23+
24+
for interface in SCNetworkInterface::list() {
25+
println!("{:?}\n\n", interface);
26+
}
27+
}

system-configuration/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
2020
#[macro_use]
2121
extern crate core_foundation;
22+
extern crate core_foundation_sys;
2223
extern crate system_configuration_sys;
2324

2425
pub mod dynamic_store;
26+
pub mod network_configuration;

0 commit comments

Comments
 (0)