#ethernet #ioctl #linux #ethtool #command #info #siocethtool

ethernet-info

A library uses SIOCETHTOOL ioctl command to get ethernet information

3 releases

0.0.4 Feb 29, 2024
0.0.3 Sep 6, 2023
0.0.2 Aug 6, 2023

#406 in Unix APIs

Download history 34/week @ 2024-07-25 6/week @ 2024-08-01 6/week @ 2024-09-19 4/week @ 2024-09-26

102 downloads per month

GPL-2.0 license

42KB
781 lines

Ethernet Info

crates.io docs.rs ci coverage

The crate provides a way to get the link information of the interface, including the port type, supported modes. The crate is based on the ioctl command, so it can only be used on Linux.

Examples

List all the interfaces' ethtool related information.

use ethernet_info::get_ethernet_info;
let interfaces_eth_info = get_ethernet_info(None);
for interface_info in interfaces_eth_info {
    println!("interface: {}", interface_info.name());
    println!("Port: {}", interface_info.port());
    println!("Supported Ports: {:?}", interface_info.ports());
    println!("Supported: {:?}", interface_info.supported());
}

Get the ethtool related information of the specified interface.

use ethernet_info::get_ethernet_info;
let interfaces_eth_info = get_ethernet_info(Some("enp1s0"));
for interface_info in interfaces_eth_info {
    println!("interface: {}", interface_info.name());
    println!("Port: {}", interface_info.port());
    println!("Supported Ports: {:?}", interface_info.ports());
    println!("Supported: {:?}", interface_info.supported());
}

Get the ethtool related of the specified interface by EthernetInfo.

use ethernet_info::EthernetInfo;
if let Ok(interface_info) = EthernetInfo::try_from("enp1s0") {
    println!("interface: {}", interface_info.name());
    println!("Port: {}", interface_info.port());
    println!("Supported Ports: {:?}", interface_info.ports());
    println!("Supported: {:?}", interface_info.supported());
}

Test

This crate depends on hardware, some tests may not be passed on every machine. Please change the test option on your own.

Dependencies

~2.5MB
~51K SLoC