Skip to content

Avoid Winsock provider loading for local hostname lookups - #892

Open
Steve Lee (SteveL-MSFT) wants to merge 1 commit into
latestw_allfrom
stevel-msft-hostname-lookup-optimization
Open

Steve Lee (SteveL-MSFT) wants to merge 1 commit into
latestw_allfrom
stevel-msft-hostname-lookup-optimization

Conversation

@SteveL-MSFT

Copy link
Copy Markdown
Member

Local hostname lookup currently invokes Winsock, loading network namespace providers unnecessarily during ssh-keygen startup.

Use GetComputerNameExW(ComputerNameDnsHostname) and convert the result to UTF-8 without heap allocation. Retain Winsock as a fallback if the native lookup fails, and report invalid or insufficient buffers through errno. Add regression checks for hostname equality, exact-fit buffers, invalid buffers, and avoiding additional DNS provider loading.

Validation: A focused harness compiled the exact production function with VS 2022 /W4 /WX and passed native hostname, provider-loading, UTF-8 boundary, fallback, and error-mapping checks. The full repository build and unit suite remain unverified because the required VS 2026 ARM64 tools are unavailable on this machine.

Fixes PowerShell/Win32-OpenSSH#2493

Use GetComputerNameExW with UTF-8 conversion and retain Winsock as a fallback. Validate buffer sizes and add hostname regression coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 20:59
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the Windows hostname-lookup change.

No open issues 🎉

What changed in this PR

This PR updates the Windows compatibility layer to avoid unnecessary Winsock namespace-provider loading during local hostname lookups, reducing startup work for ssh-keygen.

Changes:

  • Uses GetComputerNameExW with stack-based UTF-8 conversion, retaining Winsock as a fallback.
  • Reports invalid and insufficient buffers through errno.
  • Adds regression checks for hostname equality, exact-fit buffers, invalid buffers, and additional dnsapi.dll loading.

The reported focused harness passed; the full repository build and unit suite remain unverified.

File Description
regress/​unittests/​win32compat/​socket_tests.c Adds hostname, buffer-boundary, error, and provider-loading checks.
contrib/​win32/​win32compat/​socketio.c Implements native hostname retrieval, UTF-8 conversion, and Winsock fallback.

Review effort: Balanced

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.

ssh-keygen spends about 12 ms at start-up in Winsock gethostname()

2 participants