Skip to content

List the network interfaces on Windows too - #116

Merged
fylorn merged 1 commit into
mainfrom
feat/windows-nics
Sep 23, 2026
Merged

fylorn merged 1 commit into
mainfrom
feat/windows-nics

Conversation

@fylorn

@fylorn fylorn commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

getifaddrs, freeifaddrs and if_nametoindex sat in this module with no cfg around them at all — so it was not that the interface picker would come up empty on Windows, it was that the crate would not build.

Windows answers the same question through GetAdaptersAddresses. Both systems are asked directly and windows-sys is a pure-Rust binding that compiles no C, which is the same trade this module already made by reaching for libc instead of a cross-platform wrapper: the two sides together are under 150 lines, and the choices a wrapper would have to make between the two semantics are exactly what the comments here are about.

What moved out of the platform code

Skipping link-local IPv6 and sorting loopback last are rules about the picker, not about how a system hands us its interfaces. They are now shared and tested once; the platform modules only read.

Two Windows-specific calls worth flagging in review

The name is FriendlyName, not AdapterName. The latter is a GUID like {3F2504E0-…}. The configuration stores this name, so it has to survive a restart and be something the user recognises — the picker shows what they saw in system settings ("Wi-Fi", "以太网"). A GUID satisfies only the first, and a bind: value nobody can read pushes the user back to copying an address from somewhere else.

The buffer is a Vec<u64>, not a Vec<u8>. We read it back as IP_ADAPTER_ADDRESSES_LH, and Vec<u8> only promises one-byte alignment. That is undefined behaviour that no compiler and no test would report, and on x86 it would most likely appear to work. A const assertion keeps "u64's alignment covers that struct" true in the future.

How the Windows branch was verified from macOS

The whole workspace cannot cross-check — blake3's assembly wants ml64.exe. One self-contained file can: pulled into a scratch crate via #[path] with only windows-sys, then

cargo check --target x86_64-pc-windows-msvc
cargo check --target aarch64-pc-windows-msvc

Both clean. The method was itself checked by deliberately misspelling a field in the Windows branch and confirming it failed — a cfg'd-out module that "passes" and one that was never compiled look identical otherwise. It caught a missing Win32_NetworkManagement_Ndis feature that would have waited for a Windows runner to exist.

This does not replace Windows CI: linking, runtime behaviour and anything outside cfg(windows) still need a real runner. It replaces writing blind and letting CI find the typos.

Verified

cargo clippy --workspace --all-targets -- -D warnings clean, full workspace test suite green, and the six unit tests (two new: a non-ASCII interface name staying one row, and the link-local rule on its own) pass on macOS.

🤖 Generated with Claude Code

`getifaddrs`, `freeifaddrs` and `if_nametoindex` sat in this module with no
cfg around them at all, so it was not that the interface picker would be
empty on Windows -- the crate would not build.

Windows answers the same question through `GetAdaptersAddresses`. The two
systems are asked separately and `windows-sys` is a pure-Rust binding that
compiles no C, which is the same trade this module already made by reaching
for libc instead of a cross-platform wrapper: together both sides are under
a hundred and fifty lines, and the choices a wrapper would have to make
between the two are exactly what the comments here are about.

What to keep and how to order it is now shared rather than written twice.
Skipping link-local IPv6 and sorting loopback last are rules about the
picker, not about how a system hands us its interfaces, so the platform
modules only read, and the module decides.

Two things are specific to Windows and worth saying out loud:

The name is `FriendlyName`, not `AdapterName`. The latter is a GUID. The
configuration stores this name, so it has to survive a restart *and* be
something the user recognises -- the picker shows what they saw in system
settings. A GUID is only the first of those, and a `bind:` value nobody can
read pushes them back to copying an address from somewhere else.

The buffer is a `Vec<u64>`, not a `Vec<u8>`, because we read it back as
`IP_ADAPTER_ADDRESSES_LH` and `Vec<u8>` only promises one-byte alignment.
That is undefined behaviour that no compiler and no test would report, and
on x86 it would most likely appear to work. A const assertion keeps the
claim that `u64` covers that alignment true in the future.

Verified by checking this module on its own against both
`x86_64-pc-windows-msvc` and `aarch64-pc-windows-msvc` -- the whole
workspace cannot cross-check from macOS (blake3 wants ml64.exe), but one
self-contained file can, and it caught a missing windows-sys feature that
would otherwise have waited for a Windows runner to exist.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 45b58b6 into main Sep 23, 2026
1 check passed
@fylorn
fylorn deleted the feat/windows-nics branch September 23, 2026 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant