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

Open
github-bot wants to merge 2 commits from github-bot/gh-2242 into main AGit
Owner

@⁠syfyra on GitHub · 2026-11-26 10:11 UTC · original
syfyra:fix/ws2-connect-by-name-v6 → main · +125 −8 · 3 files · 2 commits · draft

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:

  • ws2_offline_test gets a section 8: WSAConnectByNameA connects an IPv4 socket to localhost at 127.0.0.1, WSAConnectByNameA and WSAConnectByNameW connect a default IPv6 socket at ::1, and a dual-mode IPv6 socket at ::ffff:127.0.0.1 (skipped where IPv6 loopback is unavailable).
    • main: the two IPv6-only checks fail.
    • this branch: 76 of 76 checks pass, in 3 of 3 runs.
  • ctest -j 8 over the 168 CPU tests, with this branch and WS2-UDP-DISCONNECT (#2241) merged: all pass except xmem_no_write_watch, whose split-reader check is the start race #2131 fixes (it passes on its own).
  • scripts/check_no_game_data.py on both files.

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

**@⁠syfyra** on GitHub · 2026-11-26 10:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2242) `syfyra:fix/ws2-connect-by-name-v6` → `main` · +125 −8 · 3 files · 2 commits · draft 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: - `ws2_offline_test` gets a section 8: `WSAConnectByNameA` connects an IPv4 socket to localhost at `127.0.0.1`, `WSAConnectByNameA` and `WSAConnectByNameW` connect a default IPv6 socket at `::1`, and a dual-mode IPv6 socket at `::ffff:127.0.0.1` (skipped where IPv6 loopback is unavailable). - `main`: the two IPv6-only checks fail. - this branch: 76 of 76 checks pass, in 3 of 3 runs. - `ctest -j 8` over the 168 CPU tests, with this branch and WS2-UDP-DISCONNECT (#2241) merged: all pass except `xmem_no_write_watch`, whose split-reader check is the start race #2131 fixes (it passes on its own). - `scripts/check_no_game_data.py` on both files. 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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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](https://claude.com/claude-code)
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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:24:17 +00:00
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 10:58 UTC · original · reviewed

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.

**@⁠lixonik** on GitHub · 2026-11-26 10:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2242#pullrequestreview-6072924525) · **reviewed** 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 <[email protected]>
Author
Owner

@⁠syfyra on GitHub · 2026-11-26 14:33 UTC · original

Follow-up commit 664a6fc84: 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.

**@⁠syfyra** on GitHub · 2026-11-26 14:33 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2242#issuecomment-7194991162) Follow-up commit 664a6fc84: 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2242/head:github-bot/gh-2242'
git switch 'github-bot/gh-2242'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2242'
git switch 'github-bot/gh-2242'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2242'
git switch 'github-bot/gh-2242'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2242'
git switch 'main'
git merge --squash 'github-bot/gh-2242'
git switch 'main'
git merge --ff-only 'github-bot/gh-2242'
git switch 'main'
git merge 'github-bot/gh-2242'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.