Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

eth0 interface getting listed 3 times

I am on WSL 2 and using the nix crate in Rust and listing the network interfaces as shown below:

let ifaces = nix::ifaddrs::getifaddrs().unwrap();

for iface in ifaces {
    println!("{:#?}", iface);
}

When I do this, it strangely lists eth0 three times. Once with netmask as None, and once with broadcast as None.

Anyone know why it’s being listed 3 separate times? Or is it an issue with my WSL config? I’d expect it to only show up once, like in the result of running ip show link.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’ve provided the 3 listing below.

InterfaceAddress {
    interface_name: "eth0",
    flags: IFF_UP | IFF_BROADCAST | IFF_RUNNING | IFF_MULTICAST | IFF_LOWER_UP | IFF_NO_PI | IFF_TUN | IFF_TAP,
    address: Some(
        SockaddrStorage {
            ss: sockaddr_storage {
                ss_family: 17,
                __ss_align: 140736544452160,
            },
        },
    ),
    netmask: None,
    broadcast: Some(
        SockaddrStorage {
            ss: sockaddr_storage {
                ss_family: 17,
                __ss_align: 140736544451856,
            },
        },
    ),
    destination: None,
}
InterfaceAddress {
    interface_name: "eth0",
    flags: IFF_UP | IFF_BROADCAST | IFF_RUNNING | IFF_MULTICAST | IFF_LOWER_UP | IFF_NO_PI | IFF_TUN | IFF_TAP,
    address: Some(
        SockaddrStorage {
            ss: sockaddr_storage {
                ss_family: 2,
                __ss_align: 94107083991267,
            },
        },
    ),
    netmask: Some(
        SockaddrStorage {
            ss: sockaddr_storage {
                ss_family: 2,
                __ss_align: 94107084128296,
            },
        },
    ),
    broadcast: Some(
        SockaddrStorage {
            ss: sockaddr_storage {
                ss_family: 2,
                __ss_align: 94107084192256,
            },
        },
    ),
    destination: None,
}
InterfaceAddress {
    interface_name: "eth0",
    flags: IFF_UP | IFF_BROADCAST | IFF_RUNNING | IFF_MULTICAST | IFF_LOWER_UP | IFF_NO_PI | IFF_TUN | IFF_TAP,
    address: Some(
        SockaddrStorage {
            ss: sockaddr_storage {
                ss_family: 10,
                __ss_align: 94107083991267,
            },
        },
    ),
    netmask: Some(
        SockaddrStorage {
            ss: sockaddr_storage {
                ss_family: 10,
                __ss_align: 94107084128296,
            },
        },
    ),
    broadcast: None,
    destination: None,
}

>Solution :

This is normal. You’re not listing interfaces, you’re listing interface addresses with getifaddr. You can have multiple addresses per interface. See, e.g., how some of them have ss_family 2, others 10? That’s IPv4 and v6 addresses. Compare with the output of ip -brief a or similar.

You probably want if_nameindex instead.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading