Skip to main content

index_to_name

Function index_to_name 

Source
pub fn index_to_name(index: InterfaceId) -> Result<IfName, Error>
Expand description

Converts an network interface index to the name.

This function just uses libc. May be a blocking call.

Examples found in repository?
examples/if_indextoname.rs (line 18)
2fn main() {
3    let args = std::env::args().collect::<Vec<_>>();
4    if args.len() < 2 {
5        println!("Usage: {} <if_index>", &args[0]);
6        std::process::exit(1);
7    }
8
9    let index = args[1].parse::<libc::c_uint>();
10    let index = match index {
11        Ok(v) => v,
12        _ => {
13            eprintln!("Invalid unsigned integer supplied");
14            std::process::exit(1);
15        },
16    };
17
18    match index_to_name(index.into()) {
19        Ok(name) => {
20            println!("{}", name);
21        },
22        _ => {
23            eprintln!("{}: No such interface", &args[0]);
24            std::process::exit(2);
25        }
26    }
27}