Add Interface TX/RX speed

main
shellrow 3 years ago
parent c49c19b62f
commit 135de73e3f
  1. 2
      examples/default_interface.rs
  2. 2
      examples/list_interfaces.rs
  3. 4
      src/interface/mod.rs
  4. 11
      src/interface/windows.rs

@ -17,6 +17,8 @@ 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); println!("\tFlags: {:?}", default_interface.flags);
println!("\tTransmit Speed: {:?}", default_interface.transmit_speed);
println!("\tReceive Speed: {:?}", default_interface.receive_speed);
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);

@ -17,6 +17,8 @@ fn main(){
println!("\tIPv4: {:?}", interface.ipv4); println!("\tIPv4: {:?}", interface.ipv4);
println!("\tIPv6: {:?}", interface.ipv6); println!("\tIPv6: {:?}", interface.ipv6);
println!("\tFlags: {:?}", interface.flags); println!("\tFlags: {:?}", interface.flags);
println!("\tTransmit Speed: {:?}", interface.transmit_speed);
println!("\tReceive Speed: {:?}", interface.receive_speed);
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);

@ -89,6 +89,10 @@ pub struct Interface {
pub ipv6: Vec<Ipv6Net>, pub ipv6: Vec<Ipv6Net>,
/// Flags for the network interface (OS Specific) /// Flags for the network interface (OS Specific)
pub flags: u32, pub flags: u32,
/// Speed in bits per second of the transmit for the network interface
pub transmit_speed: Option<u64>,
/// Speed in bits per second of the receive for the network interface
pub receive_speed: Option<u64>,
/// Default gateway for the network interface /// Default gateway for the network interface
pub gateway: Option<Gateway>, pub gateway: Option<Gateway>,
} }

@ -91,12 +91,15 @@ pub fn interfaces() -> Vec<Interface> {
// Description // Description
let p_desc = unsafe { (*cur).Description.0}; let p_desc = unsafe { (*cur).Description.0};
let desc_len = unsafe { wcslen(p_desc as *const wchar_t) }; let desc_len = unsafe { wcslen(p_desc as *const wchar_t) };
let aname_slice = unsafe { std::slice::from_raw_parts(p_desc, desc_len) }; let desc_slice = unsafe { std::slice::from_raw_parts(p_desc, desc_len) };
let description = String::from_utf16(aname_slice).unwrap(); let description = String::from_utf16(desc_slice).unwrap();
// MAC address // MAC address
let mac_addr_arr: [u8; 6] = unsafe { (*cur).PhysicalAddress }[..6].try_into().unwrap_or([0, 0, 0, 0, 0, 0]); let mac_addr_arr: [u8; 6] = unsafe { (*cur).PhysicalAddress }[..6].try_into().unwrap_or([0, 0, 0, 0, 0, 0]);
let mac_addr: MacAddr = MacAddr::new(mac_addr_arr); let mac_addr: MacAddr = MacAddr::new(mac_addr_arr);
// TransmitLinkSpeed (bits per second)
let transmit_speed = unsafe { (*cur).TransmitLinkSpeed};
// ReceiveLinkSpeed (bits per second)
let receive_speed = unsafe { (*cur).ReceiveLinkSpeed};
let mut ipv4_vec: Vec<Ipv4Net> = vec![]; let mut ipv4_vec: Vec<Ipv4Net> = vec![];
let mut ipv6_vec: Vec<Ipv6Net> = vec![]; let mut ipv6_vec: Vec<Ipv6Net> = vec![];
// Enumerate all IPs // Enumerate all IPs
@ -168,6 +171,8 @@ pub fn interfaces() -> Vec<Interface> {
ipv4: ipv4_vec, ipv4: ipv4_vec,
ipv6: ipv6_vec, ipv6: ipv6_vec,
flags: flags, flags: flags,
transmit_speed: Some(transmit_speed),
receive_speed: Some(receive_speed),
gateway: default_gateway, gateway: default_gateway,
}; };
interfaces.push(interface); interfaces.push(interface);

Loading…
Cancel
Save