Fix if_type exception handling (Linux)

main
shellrow 3 years ago
parent 85bb313187
commit dd966fc195
  1. 22
      src/interface/linux.rs
  2. 2
      src/interface/types.rs

@ -5,16 +5,20 @@ use crate::interface::InterfaceType;
pub fn get_interface_type(if_name: String) -> InterfaceType { pub fn get_interface_type(if_name: String) -> InterfaceType {
let if_type_path: String = format!("/sys/class/net/{}/type", if_name); let if_type_path: String = format!("/sys/class/net/{}/type", if_name);
let r = read_to_string(if_type_path); let r = read_to_string(if_type_path);
let if_type_string = match r { match r {
Ok(content) => content.trim().to_string(), Ok(content) => {
Err(_) => String::from("999"), let if_type_string = content.trim().to_string();
}; match if_type_string.parse::<u32>() {
match if_type_string.parse::<u32>() { Ok(if_type) => {
Ok(if_type) => { return InterfaceType::try_from(if_type).unwrap_or(InterfaceType::Unknown);
InterfaceType::try_from(if_type).unwrap_or(InterfaceType::Unknown) },
Err(_) => {
return InterfaceType::Unknown;
}
}
}, },
Err(_) => { Err(_) => {
InterfaceType::Unknown return InterfaceType::Unknown;
} }
} };
} }

@ -80,7 +80,7 @@ impl InterfaceType {
InterfaceType::Atm => 19, InterfaceType::Atm => 19,
InterfaceType::Wireless80211 => 801, InterfaceType::Wireless80211 => 801,
InterfaceType::Tunnel => 768, InterfaceType::Tunnel => 768,
_ => 999, _ => u32::MAX,
} }
} }

Loading…
Cancel
Save