Expand description
§getifaddrs
A cross-platform library for retrieving network interface information.
This crate provides a simple and consistent API for querying network interface details across different operating systems. It supports Unix-like systems (Linux, macOS, *BSD) and Windows.
§Features
- Retrieve network interface information (name, IP address, netmask, flags, etc.)
- Filter interfaces based on various criteria (loopback, IPv4/IPv6, name, index)
- Cross-platform support (Unix-like systems and Windows)
- Provides a cross-platform implementation of
if_indextoname
andif_nametoindex
§Usage
Add this to your Cargo.toml
:
[dependencies]
getifaddrs = "0.2"
§Example
use getifaddrs::{getifaddrs, InterfaceFlags};
fn main() -> std::io::Result<()> {
for interface in getifaddrs()? {
println!("Interface: {}", interface.name);
println!(" Address: {}", interface.address);
if let Some(netmask) = interface.netmask {
println!(" Netmask: {}", netmask);
}
println!(" Flags: {:?}", interface.flags);
if interface.flags.contains(InterfaceFlags::UP) {
println!(" Status: Up");
} else {
println!(" Status: Down");
}
println!();
}
Ok(())
}
§License
Structs§
- Interface
- Represents a network interface.
- Interface
Filter - A filter for network interfaces.
- Interface
Flags - Flags representing the status and capabilities of a network interface.
Functions§
- getifaddrs
- Returns an iterator for all network interfaces on the system.
- if_
indextoname - Converts a network interface index to its corresponding name.
- if_
nametoindex - Converts a network interface name to its corresponding index.
Type Aliases§
- Interface
Index - This represents the index of a network interface.