pub struct NetworkManager { /* private fields */ }
Implementations§
Source§impl NetworkManager
impl NetworkManager
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/hotspot.rs (line 64)
52fn run() -> Result<()> {
53 let Options {
54 interface,
55 ssid,
56 password,
57 } = parse_options();
58
59 let pass_str = match password {
60 Some(ref s) => Some(s as &str),
61 None => None,
62 };
63
64 let manager = NetworkManager::new();
65
66 let device = find_device(&manager, interface)?;
67 let wifi_device = device.as_wifi_device().unwrap();
68
69 wifi_device.create_hotspot(&ssid as &str, pass_str, None)?;
70
71 Ok(())
72}
More examples
examples/create.rs (line 54)
46fn run() -> Result<()> {
47 let args: Vec<String> = env::args().collect();
48
49 if args.len() != 3 {
50 println!("USAGE: create SSID PASSWORD");
51 process::exit(1);
52 }
53
54 let manager = NetworkManager::new();
55
56 let device = find_device(&manager)?;
57
58 let wifi_device = device.as_wifi_device().unwrap();
59
60 let access_points = wifi_device.get_access_points()?;
61
62 let ap_index = find_access_point(&access_points, &args[1] as &str)?;
63
64 let credentials = AccessPointCredentials::Wpa {
65 passphrase: args[2].clone(),
66 };
67
68 wifi_device.connect(&access_points[ap_index], &credentials)?;
69
70 Ok(())
71}
pub fn with_method_timeout(timeout: u64) -> Self
Sourcepub fn start_service(timeout: u64) -> Result<ServiceState>
pub fn start_service(timeout: u64) -> Result<ServiceState>
Starts the Network Manager service.
§Examples
use network_manager::NetworkManager;
let state = NetworkManager::start_service(10).unwrap();
println!("{:?}", state);
Sourcepub fn stop_service(timeout: u64) -> Result<ServiceState>
pub fn stop_service(timeout: u64) -> Result<ServiceState>
Stops the Network Manager service.
§Examples
use network_manager::NetworkManager;
let state = NetworkManager::stop_service(10).unwrap();
println!("{:?}", state);
Sourcepub fn get_service_state() -> Result<ServiceState>
pub fn get_service_state() -> Result<ServiceState>
Gets the state of the Network Manager service.
§Examples
use network_manager::NetworkManager;
let state = NetworkManager::get_service_state().unwrap();
println!("{:?}", state);
Sourcepub fn get_connections(&self) -> Result<Vec<Connection>>
pub fn get_connections(&self) -> Result<Vec<Connection>>
Get a list of Network Manager connections sorted by path.
§Examples
use network_manager::NetworkManager;
let manager = NetworkManager::new();
let connections = manager.get_connections().unwrap();
println!("{:?}", connections);
pub fn get_active_connections(&self) -> Result<Vec<Connection>>
Sourcepub fn get_devices(&self) -> Result<Vec<Device>>
pub fn get_devices(&self) -> Result<Vec<Device>>
Get a list of Network Manager devices.
§Examples
use network_manager::NetworkManager;
let manager = NetworkManager::new();
let devices = manager.get_devices().unwrap();
println!("{:?}", devices);
Examples found in repository?
examples/create.rs (line 74)
73fn find_device(manager: &NetworkManager) -> Result<Device> {
74 let devices = manager.get_devices()?;
75
76 let index = devices
77 .iter()
78 .position(|d| *d.device_type() == DeviceType::WiFi);
79
80 if let Some(index) = index {
81 Ok(devices[index].clone())
82 } else {
83 bail!(ErrorKind::Runtime("Cannot find a WiFi device".into()))
84 }
85}
More examples
examples/hotspot.rs (line 124)
111fn find_device(manager: &NetworkManager, interface: Option<String>) -> Result<Device> {
112 if let Some(interface) = interface {
113 let device = manager.get_device_by_interface(&interface)?;
114
115 if *device.device_type() == DeviceType::WiFi {
116 Ok(device)
117 } else {
118 bail!(ErrorKind::Runtime(format!(
119 "{} is not a WiFi device",
120 interface
121 )))
122 }
123 } else {
124 let devices = manager.get_devices()?;
125
126 let index = devices
127 .iter()
128 .position(|d| *d.device_type() == DeviceType::WiFi);
129
130 if let Some(index) = index {
131 Ok(devices[index].clone())
132 } else {
133 bail!(ErrorKind::Runtime("Cannot find a WiFi device".into()))
134 }
135 }
136}
Sourcepub fn get_device_by_interface(&self, interface: &str) -> Result<Device>
pub fn get_device_by_interface(&self, interface: &str) -> Result<Device>
Examples found in repository?
examples/hotspot.rs (line 113)
111fn find_device(manager: &NetworkManager, interface: Option<String>) -> Result<Device> {
112 if let Some(interface) = interface {
113 let device = manager.get_device_by_interface(&interface)?;
114
115 if *device.device_type() == DeviceType::WiFi {
116 Ok(device)
117 } else {
118 bail!(ErrorKind::Runtime(format!(
119 "{} is not a WiFi device",
120 interface
121 )))
122 }
123 } else {
124 let devices = manager.get_devices()?;
125
126 let index = devices
127 .iter()
128 .position(|d| *d.device_type() == DeviceType::WiFi);
129
130 if let Some(index) = index {
131 Ok(devices[index].clone())
132 } else {
133 bail!(ErrorKind::Runtime("Cannot find a WiFi device".into()))
134 }
135 }
136}
pub fn get_state(&self) -> Result<NetworkManagerState>
pub fn get_connectivity(&self) -> Result<Connectivity>
pub fn is_networking_enabled(&self) -> Result<bool>
pub fn is_wireless_enabled(&self) -> Result<bool>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NetworkManager
impl !RefUnwindSafe for NetworkManager
impl !Send for NetworkManager
impl !Sync for NetworkManager
impl Unpin for NetworkManager
impl !UnwindSafe for NetworkManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more