Skip to content

Commit

Permalink
Add High-level API
Browse files Browse the repository at this point in the history
  • Loading branch information
luozijun committed Feb 20, 2018
1 parent 290fc79 commit d7f7154
Show file tree
Hide file tree
Showing 7 changed files with 552 additions and 1 deletion.
8 changes: 8 additions & 0 deletions system-configuration-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@
extern crate core_foundation_sys;

pub mod dynamic_store;

mod preferences;
mod network_configuration;

pub use dynamic_store::*;
pub use preferences::*;
pub use network_configuration::*;

65 changes: 65 additions & 0 deletions system-configuration-sys/src/network_configuration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use core_foundation_sys::base::Boolean;
use core_foundation_sys::string::CFStringRef;
use core_foundation_sys::dictionary::CFDictionaryRef;
use core_foundation_sys::array::CFArrayRef;

use SCPreferencesRef;

use std::os::raw::{c_void, c_int};


pub type __SCNetworkInterface = c_void;
pub type SCNetworkInterfaceRef = *const __SCNetworkInterface;
pub type SCBondInterfaceRef = SCNetworkInterfaceRef;
pub type SCVLANInterfaceRef = SCNetworkInterfaceRef;

pub type __SCBondStatus = c_void;
pub type SCBondStatusRef = *const __SCBondStatus;

pub type __SCNetworkProtocol = c_void;
pub type SCNetworkProtocolRef = *const __SCNetworkProtocol;

pub type __SCNetworkService = c_void;
pub type SCNetworkServiceRef = *const __SCNetworkService;

pub type __SCNetworkSet = c_void;
pub type SCNetworkSetRef = *const __SCNetworkSet;


#[link(name = "SystemConfiguration", kind = "framework")]
extern "C" {
pub fn SCNetworkServiceCopyAll(prefs: SCPreferencesRef) -> CFArrayRef;
pub fn SCNetworkServiceCopy(prefs: SCPreferencesRef,
serviceID: CFStringRef) -> SCNetworkServiceRef;
pub fn SCNetworkServiceGetEnabled(service: SCNetworkServiceRef) -> Boolean;
pub fn SCNetworkServiceGetInterface(service: SCNetworkServiceRef) -> SCNetworkInterfaceRef;
pub fn SCNetworkServiceGetName(service: SCNetworkServiceRef) -> CFStringRef;
pub fn SCNetworkServiceGetServiceID(service: SCNetworkServiceRef) -> CFStringRef;
pub fn SCNetworkSetGetServiceOrder(set: SCNetworkSetRef) -> CFArrayRef;
pub fn SCNetworkSetCopyServices(set: SCNetworkSetRef) -> CFArrayRef;
pub fn SCNetworkSetCopyCurrent(prefs:SCPreferencesRef) -> SCNetworkSetRef;

pub fn SCNetworkInterfaceCopyAll() -> CFArrayRef;
pub fn SCNetworkInterfaceCopyMTU(interface: SCNetworkInterfaceRef,
mtu_cur: *mut c_int,
mtu_min: *mut c_int,
mtu_max: *mut c_int) -> Boolean;
pub fn SCNetworkInterfaceCopyMediaOptions(interface: SCNetworkInterfaceRef,
urrent: *mut CFDictionaryRef,
active: *mut CFDictionaryRef,
available: *mut CFArrayRef,
filter: Boolean) -> Boolean;
pub fn SCNetworkInterfaceGetBSDName(interface: SCNetworkInterfaceRef) -> CFStringRef;
pub fn SCNetworkInterfaceGetInterfaceType(interface: SCNetworkInterfaceRef) -> CFStringRef;
pub fn SCNetworkInterfaceGetHardwareAddressString(interface: SCNetworkInterfaceRef) -> CFStringRef;

pub fn SCNetworkInterfaceGetConfiguration(interface: SCNetworkInterfaceRef) -> CFDictionaryRef;
pub fn SCNetworkInterfaceGetExtendedConfiguration(interface: SCNetworkInterfaceRef,
extendedType: CFStringRef) -> CFDictionaryRef;

pub fn SCNetworkInterfaceSetConfiguration(interface: SCNetworkInterfaceRef,
config: CFDictionaryRef) -> Boolean;
pub fn SCNetworkInterfaceSetExtendedConfiguration(interface: SCNetworkInterfaceRef,
extendedType: CFStringRef,
config: CFDictionaryRef) -> Boolean;
}
16 changes: 16 additions & 0 deletions system-configuration-sys/src/preferences.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use core_foundation_sys::base::CFAllocatorRef;
use core_foundation_sys::string::CFStringRef;

use std::os::raw::c_void;


pub type __SCPreferences = c_void;
pub type SCPreferencesRef = *const __SCPreferences;


#[link(name = "SystemConfiguration", kind = "framework")]
extern "C" {
pub fn SCPreferencesCreate(allocator: CFAllocatorRef,
name: CFStringRef,
prefsID: CFStringRef) -> SCPreferencesRef;
}
2 changes: 1 addition & 1 deletion system-configuration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ readme = "../README.md"

[dependencies]
core-foundation = "0.5"

core-foundation-sys = "0.5"
system-configuration-sys = { path = "../system-configuration-sys", version = "0.1" }
23 changes: 23 additions & 0 deletions system-configuration/examples/dns.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
extern crate system_configuration;

use system_configuration::network_configuration::{
// SCNetworkInterfaceMTU, SCNetworkServiceDNS,
SCNetworkGlobal, SCNetworkService, SCNetworkInterface
};


fn main (){
println!("{:?}", SCNetworkGlobal.service());

println!("{:?}", SCNetworkGlobal.interface());

println!("{:?}", SCNetworkGlobal.router());

for service in SCNetworkService::list_order() {
println!("{:?}\n\n", service);
}

println!("{:?}", SCNetworkService::list());

println!("{:?}", SCNetworkInterface::list());
}
2 changes: 2 additions & 0 deletions system-configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#[macro_use]
extern crate core_foundation;
extern crate core_foundation_sys;
extern crate system_configuration_sys;

pub mod dynamic_store;
pub mod network_configuration;
Loading

0 comments on commit d7f7154

Please sign in to comment.