Net: connect to a zero address disconnects a datagram socket instead of being refused (fixes #891) #1071

Closed
github-bot wants to merge 1 commit from gh-pr/1071/head into gh-pr/1071/base
Owner

@⁠acleofe on GitHub · 2026-11-24 15:27 UTC · original
fix/net-connect-zero-address → main · +56 −2 · 1 files · 1 commits · closed without merging

What

connect and WSAConnect pass an address that reaches no one to the host: an IPv4/IPv6 address of zeros, or a sockaddr of no family (AF_UNSPEC). Every other address is vetted as before, so only loopback connects.

Why

Winsock documents that connecting a datagram socket to an address of zeros dissolves its association with its peer. The offline policy refused that address as off the machine (WSAENETUNREACH), so a connected UDP socket stayed connected. An address of zeros never leaves the machine (a stream socket cannot connect to it on Windows), so passing it on does not weaken the policy.

Test

  • a_zero_address_disconnects_a_datagram_socket: a UDP socket connected to a loopback peer is disconnected (getpeername gives WSAENOTCONN) by connect with 0.0.0.0:0 and with a zeroed AF_UNSPEC sockaddr, and by WSAConnect; an off-machine address is still refused with WSAENETUNREACH. Before this change the first zero-address connect returned SOCKET_ERROR.
  • cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings and cargo test --workspace --locked pass.

🤖 Generated with Claude Code

**@⁠acleofe** on GitHub · 2026-11-24 15:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/1071) `fix/net-connect-zero-address` → `main` · +56 −2 · 1 files · 1 commits · closed without merging ## What `connect` and `WSAConnect` pass an address that reaches no one to the host: an IPv4/IPv6 address of zeros, or a `sockaddr` of no family (`AF_UNSPEC`). Every other address is vetted as before, so only loopback connects. ## Why Winsock documents that connecting a datagram socket to an address of zeros dissolves its association with its peer. The offline policy refused that address as off the machine (`WSAENETUNREACH`), so a connected UDP socket stayed connected. An address of zeros never leaves the machine (a stream socket cannot connect to it on Windows), so passing it on does not weaken the policy. ## Test - `a_zero_address_disconnects_a_datagram_socket`: a UDP socket connected to a loopback peer is disconnected (`getpeername` gives `WSAENOTCONN`) by `connect` with `0.0.0.0:0` and with a zeroed `AF_UNSPEC` sockaddr, and by `WSAConnect`; an off-machine address is still refused with `WSAENETUNREACH`. Before this change the first zero-address `connect` returned `SOCKET_ERROR`. - `cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings` and `cargo test --workspace --locked` pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Winsock disconnects a datagram socket connected to an address of zeros.
The offline policy refused that address as off the machine; it reaches
no one, so it now goes to the host.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:18:57 +00:00
github-bot closed this pull request 2026-11-26 04:18:57 +00:00
Author
Owner

@⁠ThomasHFWright on GitHub · 2026-11-24 15:53 UTC · original

Independent Linux/Wine validation of d9741ec66ce5efd505aef2d51e75f53561af64b2, base ffe310e: the new regression fails under Wine 11.22, at net.rs:939 (assert!(!connected(u))). The zero-address connect returns success, but getpeername still succeeds.

I compared direct ws2_32 calls with VIctory's wrappers in a separate diagnostic checkout. With a fresh IPv4 UDP socket connected to a loopback peer for every case, raw connect, wrapped connect, raw WSAConnect, and wrapped WSAConnect all give the same results:

Disconnect argument Connect result getpeername afterward One-byte send afterward
IPv4 0.0.0.0:0 0 0, peer 0.0.0.0:0 1 byte accepted
Zeroed AF_UNSPEC sockaddr 0 -1, WSAENOTCONN (10057) -1, WSAENOTCONN (10057)

The wrapper still rejects the off-machine test address with WSAENETUNREACH in every diagnostic case. All calls ran inside a network namespace with loopback only.

This isolates the discrepancy to the host Winsock behavior on this Wine setup, rather than the new forwarding branch. Microsoft's connect documentation specifies that the zero-address datagram operation disconnects and subsequent send returns WSAENOTCONN. The working AF_UNSPEC path is useful evidence for a Wine compatibility follow-up; I have not changed production code or checked IPv6 here.

Full workspace unit/integration suite on the unmodified PR, all features, all 14 generated Windows MSVC test executables: 341 passed, 6 failed, 6 ignored. Matched baseline: 341 passed, 5 failed, 6 ignored. The extra failure is the new disconnect test. The other five remain the empty pipeline library (#347), missing Wine Winsock export (#217), checksum-rejection expectation, nested Cargo fixture build, and Windows xtask attempting to launch host Git. Native xtask separately passes all 4 tests; asset policy passes. Both Windows-target workspace Clippy configurations (all targets, with and without all features, -D warnings) pass.

Environment: Rust 1.98.1, Wine 11.22, RTX 5090 / NVIDIA 620.73.04, vkd3d-proton 30b0eb9bc12dc9f; native d3dcompiler_47 for GPU fixtures, same runtime DLLs as baseline. Offline and offscreen. No game data, gameplay, native Windows/WARP, or Wine doctests. Aggregate counts include existing tests that return early without optional console compilers/DXIL validator. AI-assisted testing with Codex.

**@⁠ThomasHFWright** on GitHub · 2026-11-24 15:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/1071#issuecomment-7136785135) Independent Linux/Wine validation of `d9741ec66ce5efd505aef2d51e75f53561af64b2`, base `ffe310e`: the new regression **fails under Wine 11.22**, at `net.rs:939` (`assert!(!connected(u))`). The zero-address `connect` returns success, but `getpeername` still succeeds. I compared direct `ws2_32` calls with VIctory's wrappers in a separate diagnostic checkout. With a fresh IPv4 UDP socket connected to a loopback peer for every case, **raw `connect`, wrapped `connect`, raw `WSAConnect`, and wrapped `WSAConnect` all give the same results**: | Disconnect argument | Connect result | `getpeername` afterward | One-byte `send` afterward | | --- | --- | --- | --- | | IPv4 `0.0.0.0:0` | 0 | 0, peer `0.0.0.0:0` | 1 byte accepted | | Zeroed `AF_UNSPEC` sockaddr | 0 | -1, `WSAENOTCONN` (10057) | -1, `WSAENOTCONN` (10057) | The wrapper still rejects the off-machine test address with `WSAENETUNREACH` in every diagnostic case. All calls ran inside a network namespace with loopback only. This isolates the discrepancy to the host Winsock behavior on this Wine setup, rather than the new forwarding branch. [Microsoft's `connect` documentation](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect#remarks) specifies that the zero-address datagram operation disconnects and subsequent `send` returns `WSAENOTCONN`. The working `AF_UNSPEC` path is useful evidence for a Wine compatibility follow-up; I have not changed production code or checked IPv6 here. Full workspace unit/integration suite on the **unmodified PR**, all features, all 14 generated Windows MSVC test executables: **341 passed, 6 failed, 6 ignored**. Matched baseline: **341 passed, 5 failed, 6 ignored**. The extra failure is the new disconnect test. The other five remain the empty pipeline library (#347), missing Wine Winsock export (#217), checksum-rejection expectation, nested Cargo fixture build, and Windows xtask attempting to launch host Git. Native xtask separately passes all 4 tests; asset policy passes. Both Windows-target workspace Clippy configurations (all targets, with and without all features, `-D warnings`) pass. Environment: Rust 1.98.1, Wine 11.22, RTX 5090 / NVIDIA 620.73.04, vkd3d-proton `30b0eb9bc12dc9f`; native `d3dcompiler_47` for GPU fixtures, same runtime DLLs as baseline. Offline and offscreen. No game data, gameplay, native Windows/WARP, or Wine doctests. Aggregate counts include existing tests that return early without optional console compilers/DXIL validator. AI-assisted testing with Codex.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 16:29 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at d9741ec: cargo test -p victory-hle passes, 96 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 16:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1071#issuecomment-7137759915) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at d9741ec: `cargo test -p victory-hle` passes, 96 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1071
No description provided.