list_device_names

Function list_device_names 

Source
pub fn list_device_names() -> Option<Vec<String>>
Expand description

List all available wireguard devices

Returns a list of Strings. These are copies generated from the singular *mut i8 string returned by the wgbindraw-sys crate.

The copies are generated because we have no knowledge how long the c-string is valid. Hence we copy the values and gain ownership of the information.

Another reason is the original format looks like this:

“first\0second\0third\0forth\0last\0\0”

severval \0 terminated strings with in a \0 terminated string. We extract each substring and put it on the Heap. From that point on we are safe.

§Example

 
  use wgbind::list_device_names; 
 
  let names : Vec<String> = list_device_names().unwrap_or_default();
 
  for name in &names {
   
    println!("{}",name);
  }
 
  assert_eq!(names.len(), 0);