shellrow / netdev

Cross-platform library for network interface and gateway. Written in Rust.
MIT License
65 stars 12 forks source link

Created network interfaces aren't in `get_interfaces` on Windows #87

Open AaronKutch opened 2 days ago

AaronKutch commented 2 days ago

I like that this has more features and details than the network-interface crate, but it has problems on Windows.

[package]
name = "testbin"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
netdev = "0.30"
network-interface = "2.0"
tun2 = { version = "3" }
use tun2::{configure, create};

fn main() {
    let device = create(configure().tun_name("utun42").up()).unwrap();

    for ni in
        <network_interface::NetworkInterface as network_interface::NetworkInterfaceConfig>::show()
            .unwrap()
    {
        dbg!(ni.name);
    }
    for ni in netdev::get_interfaces() {
        dbg!(ni.name);
        dbg!(ni.friendly_name);
    }

    drop(device);
}

Running on Linux with cargo b && sudo ./target/debug/testbin gives exactly what I expect,

[src/main.rs:10:9] ni.name = "eth0"
[src/main.rs:10:9] ni.name = "utun42"
[src/main.rs:10:9] ni.name = "lo"
[src/main.rs:13:9] ni.name = "lo"
[src/main.rs:14:9] ni.friendly_name = None
[src/main.rs:13:9] ni.name = "eth0"
[src/main.rs:14:9] ni.friendly_name = None
[src/main.rs:13:9] ni.name = "utun42"
[src/main.rs:14:9] ni.friendly_name = None

But on Windows (cargo r, copy the DLL from https://github.com/tun2proxy/wintun-bindings/tree/master/wintun/bin/amd64 into the /target/debug folder and run cargo r in a privileged shell), I get

[src/main.rs:10:9] ni.name = "utun42"
[src/main.rs:10:9] ni.name = "Ethernet 2"
...
[src/main.rs:13:9] ni.name = "{E5A5F923-716B-487F-B647-0523E95CE909}"
[src/main.rs:14:9] ni.friendly_name = Some(
    "Ethernet 2",
)
...

Besides being inconsistent with the name and friendly_name (it should preferably set friendly_name to the same as name if it doesn't exest, so that I don't have to configure around it), it doesn't show "utun42" on windows.

AaronKutch commented 2 days ago

Also, is it possible to look up an interface by ID (I am currently only looking up by name for workaround reasons) instead of needing to iterate through an array?