Repository navigation
List the network interfaces on Windows too - #116
Merged
Merged
Conversation
`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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
getifaddrs,freeifaddrsandif_nametoindexsat 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 andwindows-sysis 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, notAdapterName. 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 abind:value nobody can read pushes the user back to copying an address from somewhere else.The buffer is a
Vec<u64>, not aVec<u8>. We read it back asIP_ADAPTER_ADDRESSES_LH, andVec<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. Aconstassertion 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 onlywindows-sys, thenBoth 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_Ndisfeature 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 warningsclean, 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