Skip to content

ws2_offline: connect an IPv6-only socket to localhost at ::1 (WS2-CONNECT-BY-NAME-V6) - #2242

Draft
syfyra wants to merge 2 commits into
ProjectLeonida:mainfrom
syfyra:fix/ws2-connect-by-name-v6
Draft

syfyra wants to merge 2 commits into
ProjectLeonida:mainfrom
syfyra:fix/ws2-connect-by-name-v6

Conversation

@syfyra

@syfyra syfyra commented Nov 26, 2026

Copy link
Copy Markdown

Claimed in the coordination issue as: WS2-CONNECT-BY-NAME-V6 (claim comment to follow)

What and why

runtime/shims/ws2_offline.cpp hands "localhost" to the host's WSAConnectByNameA/W as the literal 127.0.0.1, so the hosts file is never read. Windows itself resolves the name to ::1 and 127.0.0.1 and tries them in turn. An IPv6 socket with IPV6_V6ONLY set, which is Windows' default for AF_INET6, can reach only ::1: given 127.0.0.1, the host fails with WSAHOST_NOT_FOUND. A title that creates an IPv6 socket and connects it to "localhost" by name therefore always failed under the shim.

Measured with a small probe on Windows 11, with TCP listeners on ::1 and 127.0.0.1 at one port:

socket "localhost" "127.0.0.1" "::1"
AF_INET6, default (V6ONLY) connects to ::1 WSAHOST_NOT_FOUND connects to ::1
AF_INET6, V6ONLY off connects to ::1 connects to ::ffff:127.0.0.1 connects to ::1
AF_INET connects to 127.0.0.1 connects to 127.0.0.1 WSAHOST_NOT_FOUND

The shim now asks the host for the socket's family (SO_PROTOCOL_INFOW) and IPV6_V6ONLY, and gives an IPv6-only socket the ::1 literal. IPv4 and dual-mode IPv6 sockets keep 127.0.0.1, which both reach. A dual-mode socket whose server listens on ::1 only still differs from Windows, as on main: one literal cannot fall back like the host's resolver does.

Tested

Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo:

Not tested under Wine.

This and WS2-UDP-DISCONNECT (#2241) both change ws2_offline.cpp and its test, in different places; they merge cleanly in either order.

GPUs tested: n/a (CPU tests)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

…NECT-BY-NAME-V6)

WSAConnectByNameA/W hand "localhost" to the host as the literal
127.0.0.1 so the hosts file is never read. Windows itself resolves the
name to ::1 and 127.0.0.1 and tries them in turn, and an IPv6 socket
with IPV6_V6ONLY set, Windows' default, can reach only ::1: given
127.0.0.1 the host fails with WSAHOST_NOT_FOUND. A title that creates
an IPv6 socket and connects it by name to localhost therefore always
failed under the shim, and succeeds on Windows.

Such a socket now gets the ::1 literal. IPv4 and dual-mode IPv6
sockets keep 127.0.0.1, which both reach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Built ws2_offline_test at this head with MSVC on Windows 11. CTest passed with 76 checks and zero failures, including IPv6-only WSAConnectByNameA/W against an ::1 listener and the IPv4 and dual-mode controls. No findings from these checks.

AI-assisted.

The Winsock2 section still described the shim before this change; it now names the new behaviour and the test that covers it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@syfyra

syfyra commented Nov 26, 2026

Copy link
Copy Markdown
Author

Follow-up commit 664a6fc: the Winsock2 section of docs/runtime_imports.md still said WSAConnectByNameA/W pass localhost as 127.0.0.1. It now says ::1 for an IPv6 socket with IPV6_V6ONLY set and 127.0.0.1 for an IPv4 or dual-mode socket, and its test summary names the new check. Docs only; tests/test_docs_links.py and tests/test_docs_cli_flags.py pass. It merges cleanly with #2241 and #2341, which edit the same section on other lines.

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