Fix interfaces() on Windows when ipconfig is missing#1
Merged
Conversation
Some Windows systems don't have ipconfig.exe on PATH, which
caused System.cmd("ipconfig", []) to crash and made
interfaces() return an empty MapSet. As a result, NetworkMonitor
saw all interfaces as down and downstream code (like direct P2P
connections) couldn't get a usable local address.
- Try the cross-platform :inet.getifaddrs/0 first on Windows
(no subprocess required).
- Only fall back to parsing 'ipconfig' output if that returns
nothing usable, and resolve the binary via System32 absolute
paths (using %SystemRoot% / %WINDIR% and the canonical
C:\Windows path) before trying the bare "ipconfig" lookup.
- Use System.find_executable/1 so a missing binary returns nil
instead of raising.
There was a problem hiding this comment.
Code Review
This pull request improves network interface detection on Windows by prioritizing the cross-platform :inet.getifaddrs/0 function, which avoids spawning a subprocess. It also enhances the fallback mechanism by searching for the ipconfig.exe binary in common system directories (e.g., System32) if it is not available in the system PATH. I have no feedback to provide.
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.
Problem
Some Windows systems don't have
ipconfig.exeonPATH. When that happens,NetworkMonitor.interfaces/0calls:…which raises
ErlangError, the GenServer crashes duringstart/2→interfaces/0, and downstream code (e.g. NIC change detection, direct P2P connections in DiodeClient) can't see any interfaces.Tracked alongside diodechain/ddrive#930.
Fix
:inet.getifaddrs/0first (no subprocess required, supported on Windows).ipconfigoutput if:inet.getifaddrs/0returns nothing usable.%SystemRoot%\System32\ipconfig.exe(and the canonicalC:\Windows\System32\ipconfig.exepath) before trying the bare"ipconfig"lookup, usingSystem.find_executable/1so a missing binary returnsnilinstead of raising.Behavior on Linux/macOS is unchanged.