From bdd5d9a6172ef1196c06ec50fa9022d579dd19e4 Mon Sep 17 00:00:00 2001 From: shellrow <81893184+shellrow@users.noreply.github.com> Date: Sun, 27 Mar 2022 15:16:23 +0900 Subject: [PATCH] Add if_type and flags to Interface struct --- examples/default_interface.rs | 2 ++ examples/list_interfaces.rs | 2 ++ src/interface/mod.rs | 4 ++++ src/interface/windows.rs | 2 ++ 4 files changed, 10 insertions(+) diff --git a/examples/default_interface.rs b/examples/default_interface.rs index 3868df8..4aaddcd 100644 --- a/examples/default_interface.rs +++ b/examples/default_interface.rs @@ -7,6 +7,7 @@ fn main(){ println!("\tIndex: {}", default_interface.index); println!("\tName: {}", default_interface.name); println!("\tDescription: {:?}", default_interface.description); + println!("\tType: {}", default_interface.if_type.name()); if let Some(mac_addr) = default_interface.mac_addr { println!("\tMAC: {}", mac_addr); }else{ @@ -14,6 +15,7 @@ fn main(){ } println!("\tIPv4: {:?}", default_interface.ipv4); println!("\tIPv6: {:?}", default_interface.ipv6); + println!("\tFlags: {:?}", default_interface.flags); if let Some(gateway) = default_interface.gateway { println!("Default Gateway"); println!("\tMAC: {}", gateway.mac_addr); diff --git a/examples/list_interfaces.rs b/examples/list_interfaces.rs index e035159..37a27d0 100644 --- a/examples/list_interfaces.rs +++ b/examples/list_interfaces.rs @@ -7,6 +7,7 @@ fn main(){ println!("\tIndex: {}", interface.index); println!("\tName: {}", interface.name); println!("\tDescription: {:?}", interface.description); + println!("\tType: {}", interface.if_type.name()); if let Some(mac_addr) = interface.mac_addr { println!("\tMAC: {}", mac_addr); }else{ @@ -14,6 +15,7 @@ fn main(){ } println!("\tIPv4: {:?}", interface.ipv4); println!("\tIPv6: {:?}", interface.ipv6); + println!("\tFlags: {:?}", interface.flags); if let Some(gateway) = interface.gateway { println!("Gateway"); println!("\tMAC: {}", gateway.mac_addr); diff --git a/src/interface/mod.rs b/src/interface/mod.rs index 129eb54..2cf6ca9 100644 --- a/src/interface/mod.rs +++ b/src/interface/mod.rs @@ -73,12 +73,16 @@ pub struct Interface { /// /// On Windows, this field is the adapter name pub description: Option, + /// Interface Type + pub if_type: InterfaceType, /// MAC address of network interface pub mac_addr: Option, /// List of Ipv4Net for the network interface pub ipv4: Vec, /// List of Ipv6Net for the network interface pub ipv6: Vec, + /// Flags for the network interface (OS Specific) + pub flags: u32, /// Default gateway for the network interface pub gateway: Option, } diff --git a/src/interface/windows.rs b/src/interface/windows.rs index 6aec6d6..c6a513e 100644 --- a/src/interface/windows.rs +++ b/src/interface/windows.rs @@ -178,9 +178,11 @@ pub fn interfaces() -> Vec { index: adapter.Index, name: adapter_name, description: Some(adapter_desc), + if_type: InterfaceType::try_from(adapter.Type).unwrap_or(InterfaceType::Unknown), mac_addr: Some(MacAddr::new(mac_addr)), ipv4: ipv4_vec, ipv6: ipv6_vec, + flags: adapter.Type, gateway: default_gateway, }; interfaces.push(interface);