pub fn interfaces() -> Vec<Interface> {
    let inters = datalink::interfaces();

    let ifs: Vec<Interface> = inters
        .iter()
        .map(|inter| {
            /* Cannot get flags using WinPcap in Windows
            if !inter.is_up() {
                return Err(());
            }
            */

            let mut i = Interface::new();
            i.name = inter.name.clone();
            i.hardware_addr = match inter.mac {
                Some(mac) => mac,
                None => return Err(()),
            };
            i.ip_addrs = inter
                .ips
                .iter()
                .map(|ip| match ip {
                    ipnetwork::IpNetwork::V4(ref ipv4) => Ok(ipv4.ip()),
                    _ => Err(()),
                })
                .filter_map(Result::ok)
                .collect();

            // Exclude interface without any IPv4 address
            if i.ip_addrs.len() <= 0 {
                return Err(());
            }

            i.is_up = inter.is_up();
            i.is_loopback = inter.is_loopback();

            Ok(i)
        })
        .filter_map(Result::ok)
        .collect();

    ifs
}
/// Gets a list of available network interfaces for the current machine.
Gets a list of available network interfaces for the current machine.
Gets a list of available network interfaces for the current machine .
pub fn interfaces() -> Vec<Interface> {
    let inters = datalink::interfaces();
    let ifs: Vec<Interface> = inters
        .iter()
        .map(|inter| {
            /* Cannot get flags using WinPcap in Windows
            if !inter.is_up() {
                return Err(());
            }
            */
            let mut i = Interface::new();
            i.name = inter.name.clone();
            i.hardware_addr = match inter.mac {
                Some(mac) => mac,
                None => return Err(()),
            };
            i.ip_addrs = inter
                .ips
                .iter()
                .map(|ip| match ip {
                    ipnetwork::IpNetwork::V4(ref ipv4) => Ok(ipv4.ip()),
                    _ => Err(()),
                })
                .filter_map(Result::ok)
                .collect();
            // Exclude interface without any IPv4 address
            if i.ip_addrs.len() <= 0 {
                return Err(());
            }
            i.is_up = inter.is_up();
            i.is_loopback = inter.is_loopback();
            Ok(i)
        })
        .filter_map(Result::ok)
        .collect();
    ifs
}
pub fn interfaces ( ) -> Vec < Interface > { let inters = datalink :: interfaces ( ) ; let ifs : Vec < Interface > = inters . iter ( ) . map ( | inter | { /* Cannot get flags using WinPcap in Windows
            if !inter.is_up() {
                return Err(());
            }
            */ let mut i = Interface :: new ( ) ; i . name = inter . name . clone ( ) ; i . hardware_addr = match inter . mac { Some ( mac ) => mac , None => return Err ( ( ) ) , } ; i . ip_addrs = inter . ips . iter ( ) . map ( | ip | match ip { ipnetwork :: IpNetwork :: V4 ( ref ipv4 ) => Ok ( ipv4 . ip ( ) ) , _ => Err ( ( ) ) , } ) . filter_map ( Result :: ok ) . collect ( ) ; // Exclude interface without any IPv4 address if i . ip_addrs . len ( ) <= 0 { return Err ( ( ) ) ; } i . is_up = inter . is_up ( ) ; i . is_loopback = inter . is_loopback ( ) ; Ok ( i ) } ) . filter_map ( Result :: ok ) . collect ( ) ; ifs }
Gets a list of available network interfaces for the current machine.
Gets a list of available network interfaces for the current machine .