Crate sysctl [−] [src]
A simplified interface to the sysctl
system call.
Currently built for and only tested on FreeBSD.
Example: Get description and value
extern crate sysctl; #[cfg(not(target_os = "macos"))] fn main() { let ctl = "kern.osrevision"; let d: String = sysctl::description(ctl).unwrap(); println!("Description: {:?}", d); let val_enum = sysctl::value(ctl).unwrap(); if let sysctl::CtlValue::Int(val) = val_enum { println!("Value: {}", val); } } #[cfg(target_os = "macos")] fn main() { let ctl = "kern.osrevision"; let val_enum = sysctl::value(ctl).unwrap(); if let sysctl::CtlValue::Int(val) = val_enum { println!("Value: {}", val); } }
Example: Get value as struct
extern crate sysctl; extern crate libc; use libc::c_int; #[derive(Debug)] #[repr(C)] struct ClockInfo { hz: c_int, /* clock frequency */ tick: c_int, /* micro-seconds per hz tick */ spare: c_int, stathz: c_int, /* statistics clock frequency */ profhz: c_int, /* profiling clock frequency */ } fn main() { println!("{:?}", sysctl::value_as::<ClockInfo>("kern.clockrate")); }
Enums
CtlValue |
An Enum that holds all values returned by sysctl calls.
Extract inner value with |
Constants
Functions
set_value | |
value | |
value_as | |
value_oid | |
value_oid_as |