Skip to content

Windows interface names #107

@jclehner

Description

@jclehner

I'm planning to use libdnet in my nmrpflash utility, for cross platform operations such as adding ARP entries, adding IP addresses (aliases) to network interfaces, and possibly creating firewall rules. I've currently implemented these myself, but I'd prefer to use an existing library instead.

However I've noticed that Windows support, especially for intf is somewhat lacking, with intf_set not being implemented. I'm planning to change that with a pull request, but before that I'd like to discuss the interface naming on Windows.

First off, I like the fact that libdnet uses UNIX-like names on Windows, such as eth0, ppp0, etc. - I did a very similar thing in nmrpflash. At the moment however there's no API in libdnet to convert these names back to something that WinAPI can use. There's _find_ifindex, but that's for internal use only.

Since both Windows and UNIX use interface indices, it would be easy to add an intf_index field to struct intf_entry. The index can be used directly by some WinAPI functions, and can also be converted to an LUID, which in turn can be converted to the interface GUID.

While that would be a very simple change, you'd still have to keep the the whole intf->iftable stuff, which has the downside that the assigned names could differ between calls to _refresh_tables if an interface has been added/removed in the meantime.

I'd propose to keep the eth%d, ppp%d, etc. naming scheme, but make %d the interface index. On my machine this is a 1-2 digit number:

C:\> powershell -Command Get-NetAdapter

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
Ethernet 2                Realtek PCIe GbE Family Controller #2        21 Up           XX-XX-XX-XX-XX-XX         1 Gbps
Ethernet 3                Realtek USB GbE Family Controller            18 Disconnected XX-XX-XX-XX-XX-XX          0 bps
Wi-Fi 2                   802.11n USB Wireless LAN Card                11 Disconnected XX-XX-XX-XX-XX-XX          0 bps
Bluetooth Network Con...5 Bluetooth Device (Personal Area Ne...#5       9 Disconnected XX-XX-XX-XX-XX-XX         3 Mbps

so you'd end up with device names such as eth21, eth18, eth11 - not much different from Linux interface names such as enp42s0. That way, the interface names would also be consistent until the next reboot.

Please advise before I go forward with butchering intf-win32.c 😅

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions