From dd966fc1957b83987e76cddd8b4e4958e5c27b46 Mon Sep 17 00:00:00 2001 From: shellrow <81893184+shellrow@users.noreply.github.com> Date: Mon, 28 Mar 2022 22:12:35 +0900 Subject: [PATCH] Fix if_type exception handling (Linux) --- src/interface/linux.rs | 22 +++++++++++++--------- src/interface/types.rs | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/interface/linux.rs b/src/interface/linux.rs index 134fdc4..bd9fae9 100644 --- a/src/interface/linux.rs +++ b/src/interface/linux.rs @@ -5,16 +5,20 @@ use crate::interface::InterfaceType; pub fn get_interface_type(if_name: String) -> InterfaceType { let if_type_path: String = format!("/sys/class/net/{}/type", if_name); let r = read_to_string(if_type_path); - let if_type_string = match r { - Ok(content) => content.trim().to_string(), - Err(_) => String::from("999"), - }; - match if_type_string.parse::() { - Ok(if_type) => { - InterfaceType::try_from(if_type).unwrap_or(InterfaceType::Unknown) + match r { + Ok(content) => { + let if_type_string = content.trim().to_string(); + match if_type_string.parse::() { + Ok(if_type) => { + return InterfaceType::try_from(if_type).unwrap_or(InterfaceType::Unknown); + }, + Err(_) => { + return InterfaceType::Unknown; + } + } }, Err(_) => { - InterfaceType::Unknown + return InterfaceType::Unknown; } - } + }; } diff --git a/src/interface/types.rs b/src/interface/types.rs index 2dd81f1..4437962 100644 --- a/src/interface/types.rs +++ b/src/interface/types.rs @@ -80,7 +80,7 @@ impl InterfaceType { InterfaceType::Atm => 19, InterfaceType::Wireless80211 => 801, InterfaceType::Tunnel => 768, - _ => 999, + _ => u32::MAX, } }