inherface

Crates.ioinherface
lib.rsinherface
version0.2.0
created_at2025-06-11 18:31:09.64118+00
updated_at2025-06-17 21:48:36.097436+00
descriptionRetrieve a system's Network Interfaces on Linux
homepage
repositoryhttps://codeberg.org/black-cat/inherface
max_upload_size
id1708950
size49,999
Jon Picchietti (picchietti)

documentation

README

inherface

This project is used to get a linux system's network interfaces. It is a fork of network-interface, a project by Esteban Borai and others. We'll talk about why you might choose inherface vs network-interface below.

Usage

This project provides both a binary and a library.

Binary

Install with cargo install inherface then run inherface. At this moment, there are no CLI arguments to pass.

Library

Add to your project with cargo add inherface. All features except serde are enabled by default. Adjust as necessary.

Here is an example to get a specific interface by name:

use inherface::get_interfaces;

fn main() {
    // interfaces is a HashMap<String, NetworkInterface>
    let interfaces = get_interfaces().unwrap();
    let ethernet_interface = interfaces.get("eth0").expect("Interface not found");
}   

Or iterating through all interfaces:

use inherface::get_interfaces;

fn main() {
    let interfaces = get_interfaces().unwrap();
    interfaces.values().for_each(|interface| println!("{:?}", interface));
}

Would output something like:

NetworkInterface { name: "eth0", index: 2, v4_addr: [V4IfAddr { ip: 192.168.1.123, broadcast: Some(192.168.1.255), netmask: Some(255.255.255.0) }], v6_addr: [V6IfAddr { ip: <redacted>, broadcast: None, netmask: Some(ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff) }, V6IfAddr { ip: <redacted>, broadcast: None, netmask: Some(ffff:ffff:ffff:ffff::) }, V6IfAddr { ip: <redacted>, broadcast: None, netmask: Some(ffff:ffff:ffff:ffff::) }], mac_addr: Some(MacAddress { bytes: [<redacted>] }) }
NetworkInterface { name: "lo", index: 1, v4_addr: [V4IfAddr { ip: 127.0.0.1, broadcast: Some(127.255.255.255), netmask: Some(255.0.0.0) }], v6_addr: [V6IfAddr { ip: ::1, broadcast: None, netmask: Some(ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff) }], mac_addr: Some(MacAddress { bytes: [0, 0, 0, 0, 0, 0] }) }
NetworkInterface { name: "wlan0", index: 3, v4_addr: [], v6_addr: [], mac_addr: Some(MacAddress { bytes: [<redacted>] }) }

Comparison

At the time of writing...

Pros of using inherface:

  • Improved performance and added benchmarking.
  • Reduced overall code and added features to allow further reduction.
  • Fixed getting the ipv4 broadcast.
  • Added binary (see above).
  • Open license (GNU LGPL).
  • Hosted on open git forge (Codeberg).
  • Get interface by name.
  • Latest 2024 edition.

Cons of using inherface (consider using network-interface):

  • Removed support for all systems except linux.
  • Lack of CI/CD.

License

Distributed under the terms of the GNU Library General Public License (Version 2.0). See the LICENSE file for more information.

Commit count: 0

cargo fmt