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!("\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);

@ -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);

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

@ -178,9 +178,11 @@ pub fn interfaces() -> Vec<Interface> {
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);

Loading…
Cancel
Save