Add if_type and flags to Interface struct

main
shellrow 3 years ago
parent dab7f43370
commit bdd5d9a617
  1. 2
      examples/default_interface.rs
  2. 2
      examples/list_interfaces.rs
  3. 4
      src/interface/mod.rs
  4. 2
      src/interface/windows.rs

@ -7,6 +7,7 @@ fn main(){
println!("\tIndex: {}", default_interface.index); println!("\tIndex: {}", default_interface.index);
println!("\tName: {}", default_interface.name); println!("\tName: {}", default_interface.name);
println!("\tDescription: {:?}", default_interface.description); println!("\tDescription: {:?}", default_interface.description);
println!("\tType: {}", default_interface.if_type.name());
if let Some(mac_addr) = default_interface.mac_addr { if let Some(mac_addr) = default_interface.mac_addr {
println!("\tMAC: {}", mac_addr); println!("\tMAC: {}", mac_addr);
}else{ }else{
@ -14,6 +15,7 @@ fn main(){
} }
println!("\tIPv4: {:?}", default_interface.ipv4); println!("\tIPv4: {:?}", default_interface.ipv4);
println!("\tIPv6: {:?}", default_interface.ipv6); println!("\tIPv6: {:?}", default_interface.ipv6);
println!("\tFlags: {:?}", default_interface.flags);
if let Some(gateway) = default_interface.gateway { if let Some(gateway) = default_interface.gateway {
println!("Default Gateway"); println!("Default Gateway");
println!("\tMAC: {}", gateway.mac_addr); println!("\tMAC: {}", gateway.mac_addr);

@ -7,6 +7,7 @@ fn main(){
println!("\tIndex: {}", interface.index); println!("\tIndex: {}", interface.index);
println!("\tName: {}", interface.name); println!("\tName: {}", interface.name);
println!("\tDescription: {:?}", interface.description); println!("\tDescription: {:?}", interface.description);
println!("\tType: {}", interface.if_type.name());
if let Some(mac_addr) = interface.mac_addr { if let Some(mac_addr) = interface.mac_addr {
println!("\tMAC: {}", mac_addr); println!("\tMAC: {}", mac_addr);
}else{ }else{
@ -14,6 +15,7 @@ fn main(){
} }
println!("\tIPv4: {:?}", interface.ipv4); println!("\tIPv4: {:?}", interface.ipv4);
println!("\tIPv6: {:?}", interface.ipv6); println!("\tIPv6: {:?}", interface.ipv6);
println!("\tFlags: {:?}", interface.flags);
if let Some(gateway) = interface.gateway { if let Some(gateway) = interface.gateway {
println!("Gateway"); println!("Gateway");
println!("\tMAC: {}", gateway.mac_addr); println!("\tMAC: {}", gateway.mac_addr);

@ -73,12 +73,16 @@ pub struct Interface {
/// ///
/// On Windows, this field is the adapter name /// On Windows, this field is the adapter name
pub description: Option<String>, pub description: Option<String>,
/// Interface Type
pub if_type: InterfaceType,
/// MAC address of network interface /// MAC address of network interface
pub mac_addr: Option<MacAddr>, pub mac_addr: Option<MacAddr>,
/// List of Ipv4Net for the network interface /// List of Ipv4Net for the network interface
pub ipv4: Vec<Ipv4Net>, pub ipv4: Vec<Ipv4Net>,
/// List of Ipv6Net for the network interface /// List of Ipv6Net for the network interface
pub ipv6: Vec<Ipv6Net>, pub ipv6: Vec<Ipv6Net>,
/// Flags for the network interface (OS Specific)
pub flags: u32,
/// Default gateway for the network interface /// Default gateway for the network interface
pub gateway: Option<Gateway>, pub gateway: Option<Gateway>,
} }

@ -178,9 +178,11 @@ pub fn interfaces() -> Vec<Interface> {
index: adapter.Index, index: adapter.Index,
name: adapter_name, name: adapter_name,
description: Some(adapter_desc), description: Some(adapter_desc),
if_type: InterfaceType::try_from(adapter.Type).unwrap_or(InterfaceType::Unknown),
mac_addr: Some(MacAddr::new(mac_addr)), mac_addr: Some(MacAddr::new(mac_addr)),
ipv4: ipv4_vec, ipv4: ipv4_vec,
ipv6: ipv6_vec, ipv6: ipv6_vec,
flags: adapter.Type,
gateway: default_gateway, gateway: default_gateway,
}; };
interfaces.push(interface); interfaces.push(interface);

Loading…
Cancel
Save