Skip to content

Fix interfaces() on Windows when ipconfig is missing#1

Merged
dominicletz merged 1 commit into
masterfrom
cursor/fix-windows-ipconfig-fallback-636b
Apr 21, 2026
Merged

Fix interfaces() on Windows when ipconfig is missing#1
dominicletz merged 1 commit into
masterfrom
cursor/fix-windows-ipconfig-fallback-636b

Conversation

@dominicletz
Copy link
Copy Markdown
Member

Problem

Some Windows systems don't have ipconfig.exe on PATH. When that happens, NetworkMonitor.interfaces/0 calls:

System.cmd("ipconfig", [])

…which raises ErlangError, the GenServer crashes during start/2interfaces/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

  • On Windows, try the cross-platform :inet.getifaddrs/0 first (no subprocess required, supported on Windows).
  • Only fall back to parsing ipconfig output if :inet.getifaddrs/0 returns nothing usable.
  • Resolve the binary explicitly via %SystemRoot%\System32\ipconfig.exe (and the canonical C:\Windows\System32\ipconfig.exe path) before trying the bare "ipconfig" lookup, using System.find_executable/1 so a missing binary returns nil instead of raising.

Behavior on Linux/macOS is unchanged.

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.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dominicletz dominicletz marked this pull request as ready for review April 21, 2026 11:39
@dominicletz dominicletz merged commit a15b78a into master Apr 21, 2026
0 of 5 checks passed
@dominicletz dominicletz deleted the cursor/fix-windows-ipconfig-fallback-636b branch April 21, 2026 11:39
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.

2 participants