Linux support

main
shellrow 3 years ago
parent 135de73e3f
commit 32a12ef823
  1. 22
      src/interface/linux.rs
  2. 5
      src/interface/unix.rs

@ -22,3 +22,25 @@ pub fn get_interface_type(if_name: String) -> InterfaceType {
} }
}; };
} }
pub fn get_interface_speed(if_name: String) -> Option<u64> {
let if_speed_path: String = format!("/sys/class/net/{}/speed", if_name);
let r = read_to_string(if_speed_path);
match r {
Ok(content) => {
let if_speed_string = content.trim().to_string();
match if_speed_string.parse::<u64>() {
Ok(if_speed) => {
// Convert Mbps to bps
return Some(if_speed * 1000000);
},
Err(_) => {
return None;
}
}
},
Err(_) => {
return None;
}
};
}

@ -95,6 +95,9 @@ pub fn interfaces() -> Vec<Interface> {
}; };
for iface in &mut interfaces { for iface in &mut interfaces {
iface.if_type = linux::get_interface_type(iface.name.clone()); iface.if_type = linux::get_interface_type(iface.name.clone());
let if_speed: Option<u64> = linux::get_interface_speed(iface.name.clone());
iface.transmit_speed = if_speed;
iface.receive_speed = if_speed;
match local_ip { match local_ip {
IpAddr::V4(local_ipv4) => { IpAddr::V4(local_ipv4) => {
if iface.ipv4.iter().any(|x| x.addr == local_ipv4) { if iface.ipv4.iter().any(|x| x.addr == local_ipv4) {
@ -248,6 +251,8 @@ pub fn unix_interfaces() -> Vec<Interface> {
ipv4: ini_ipv4, ipv4: ini_ipv4,
ipv6: ini_ipv6, ipv6: ini_ipv6,
flags: addr_ref.ifa_flags, flags: addr_ref.ifa_flags,
transmit_speed: None,
receive_speed: None,
gateway: None, gateway: None,
}; };
let mut found: bool = false; let mut found: bool = false;

Loading…
Cancel
Save