fix(libkernel): report the wildcard local address after a UDP association is dissolved #8682

Closed
xXPBSXx wants to merge 2 commits from upstream-pr/8682 into main
xXPBSXx commented 2026-10-20 20:53:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T20:53:25Z.


What

udp_disconnect resets the local address to INADDR_ANY and keeps the port. Dissolving the association with connect to AF_UNSPEC left the host socket's local address in place, so getsockname still returned 127.0.0.1 (Windows; Linux for a socket bound to an explicit port). The socket now remembers that its association was dissolved and getsockname reports the wildcard address (IPv4 and IPv6) until the next bind or connect. The host socket itself is unchanged; the Technical debt entry for connect to AF_UNSPEC says so. guest_udp runs the check on Windows now.
Fixes #8681
Overlap: git merge-tree has conflicts with #8499 (two), #8448 (one) and #7511 (one) in Udp.cpp; the other open socket PRs (#8670, #8492, #8483, #8474, #8463, #7850, #7090) are clean. Whichever lands second rebases. pr_overlap was not run.

Tested

Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on current upstream/main + this commit: guest_udp fails without the change to Udp.cpp and passes with it; 10 other socket tests pass. python tools/check_conventions.py --base upstream/main: passes. Not tested: Linux/macOS, the IPv6 path, a console.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

Overlap note: #8344 adds independent Socket::peer tracking (socketpair getpeername) in Udp.cpp; this PR adds Socket::localAddressCleared. No behavior duplicate, but the Socket member hunks must be kept together if both land.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4942348674 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8682). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T20:53:25Z. --- ### What `udp_disconnect` resets the local address to `INADDR_ANY` and keeps the port. Dissolving the association with `connect` to `AF_UNSPEC` left the host socket's local address in place, so `getsockname` still returned `127.0.0.1` (Windows; Linux for a socket bound to an explicit port). The socket now remembers that its association was dissolved and `getsockname` reports the wildcard address (IPv4 and IPv6) until the next `bind` or `connect`. The host socket itself is unchanged; the Technical debt entry for `connect` to `AF_UNSPEC` says so. `guest_udp` runs the check on Windows now. Fixes #8681 Overlap: `git merge-tree` has conflicts with #8499 (two), #8448 (one) and #7511 (one) in `Udp.cpp`; the other open socket PRs (#8670, #8492, #8483, #8474, #8463, #7850, #7090) are clean. Whichever lands second rebases. `pr_overlap` was not run. ### Tested Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on current upstream/main + this commit: `guest_udp` fails without the change to `Udp.cpp` and passes with it; 10 other socket tests pass. `python tools/check_conventions.py --base upstream/main`: passes. Not tested: Linux/macOS, the IPv6 path, a console. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Overlap note: #8344 adds independent `Socket::peer` tracking (socketpair `getpeername`) in `Udp.cpp`; this PR adds `Socket::localAddressCleared`. No behavior duplicate, but the `Socket` member hunks must be kept together if both land.
MarcZX10 commented 2026-10-20 20:59:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T20:59:10Z.

Review: COMMENTED


The stored flag and getsockname adjustment cover both AF_INET and AF_INET6, and the description says the wildcard address is reported for both families. The new regression only exercises an IPv4 socket, so the IPv6 branch currently has no coverage (the description also notes it was not tested). Could you add an IPv6 case where the host supports it, checking the address becomes :: while the bound port is preserved after connect(AF_UNSPEC)?

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5591655207 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8682#pullrequestreview-5591655207). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T20:59:10Z. **Review:** COMMENTED --- The stored flag and `getsockname` adjustment cover both `AF_INET` and `AF_INET6`, and the description says the wildcard address is reported for both families. The new regression only exercises an IPv4 socket, so the IPv6 branch currently has no coverage (the description also notes it was not tested). Could you add an IPv6 case where the host supports it, checking the address becomes `::` while the bound port is preserved after `connect(AF_UNSPEC)`?
github-actions[bot] commented 2026-10-20 21:03:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T21:03:18Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 7511 docs/dev/debt/libkernel.md L201-202
PR 8344 core/libs/prx/libkernel/Socket/src/Udp.cpp L120
PR 9105 core/libs/prx/libkernel/Socket/src/Udp.cpp L300-310
docs/dev/debt/libkernel.md L202-203
PR 9108 core/libs/prx/libkernel/Socket/src/Udp.cpp L1270-1271
PR 9169 core/libs/prx/libkernel/Socket/src/Udp.cpp L1270-1271

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4630 docs/dev/debt/libkernel.md
PR 5021 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestUdp.cpp
PR 6149 docs/dev/debt/libkernel.md
PR 6469 docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6879 docs/dev/debt/libkernel.md
PR 6936 docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7192 docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 7447 docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md
PR 7653 docs/dev/debt/libkernel.md
PR 8520 docs/dev/debt/libkernel.md
PR 8547 docs/dev/debt/libkernel.md
PR 8726 docs/dev/debt/libkernel.md
PR 9099 docs/dev/debt/libkernel.md
PR 9137 docs/dev/debt/libkernel.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6301430581 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8682#issuecomment-6301430581). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T21:03:18Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 7511](https://www.github.com/boykopovar/AnyPS5/pull/7511) | `docs/dev/debt/libkernel.md` [L201-202](https://github.com/boykopovar/AnyPS5/blob/95d17687aed6bad81082d9bbef01cb1d9c0a384c/docs/dev/debt/libkernel.md#L201-L202) | | | | [PR 8344](https://www.github.com/boykopovar/AnyPS5/pull/8344) | `core/libs/prx/libkernel/Socket/src/Udp.cpp` [L120](https://github.com/boykopovar/AnyPS5/blob/95d17687aed6bad81082d9bbef01cb1d9c0a384c/core/libs/prx/libkernel/Socket/src/Udp.cpp#L120) | | | | [PR 9105](https://www.github.com/boykopovar/AnyPS5/pull/9105) | `core/libs/prx/libkernel/Socket/src/Udp.cpp` [L300-310](https://github.com/boykopovar/AnyPS5/blob/95d17687aed6bad81082d9bbef01cb1d9c0a384c/core/libs/prx/libkernel/Socket/src/Udp.cpp#L300-L310)<br>`docs/dev/debt/libkernel.md` [L202-203](https://github.com/boykopovar/AnyPS5/blob/95d17687aed6bad81082d9bbef01cb1d9c0a384c/docs/dev/debt/libkernel.md#L202-L203) | | | | [PR 9108](https://www.github.com/boykopovar/AnyPS5/pull/9108) | `core/libs/prx/libkernel/Socket/src/Udp.cpp` [L1270-1271](https://github.com/boykopovar/AnyPS5/blob/95d17687aed6bad81082d9bbef01cb1d9c0a384c/core/libs/prx/libkernel/Socket/src/Udp.cpp#L1270-L1271) | | | | [PR 9169](https://www.github.com/boykopovar/AnyPS5/pull/9169) | `core/libs/prx/libkernel/Socket/src/Udp.cpp` [L1270-1271](https://github.com/boykopovar/AnyPS5/blob/95d17687aed6bad81082d9bbef01cb1d9c0a384c/core/libs/prx/libkernel/Socket/src/Udp.cpp#L1270-L1271) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 4630](https://www.github.com/boykopovar/AnyPS5/pull/4630) | `docs/dev/debt/libkernel.md` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestUdp.cpp` | | [PR 6149](https://www.github.com/boykopovar/AnyPS5/pull/6149) | `docs/dev/debt/libkernel.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `docs/dev/debt/libkernel.md` | | [PR 6740](https://www.github.com/boykopovar/AnyPS5/pull/6740) | `docs/dev/debt/libkernel.md` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `docs/dev/debt/libkernel.md` | | [PR 6936](https://www.github.com/boykopovar/AnyPS5/pull/6936) | `docs/dev/debt/libkernel.md` | | [PR 7105](https://www.github.com/boykopovar/AnyPS5/pull/7105) | `docs/dev/debt/libkernel.md` | | [PR 7149](https://www.github.com/boykopovar/AnyPS5/pull/7149) | `docs/dev/debt/libkernel.md` | | [PR 7192](https://www.github.com/boykopovar/AnyPS5/pull/7192) | `docs/dev/debt/libkernel.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/Socket/src/Udp.cpp` | | [PR 7447](https://www.github.com/boykopovar/AnyPS5/pull/7447) | `docs/dev/debt/libkernel.md` | | [PR 7509](https://www.github.com/boykopovar/AnyPS5/pull/7509) | `docs/dev/debt/libkernel.md` | | [PR 7653](https://www.github.com/boykopovar/AnyPS5/pull/7653) | `docs/dev/debt/libkernel.md` | | [PR 8520](https://www.github.com/boykopovar/AnyPS5/pull/8520) | `docs/dev/debt/libkernel.md` | | [PR 8547](https://www.github.com/boykopovar/AnyPS5/pull/8547) | `docs/dev/debt/libkernel.md` | | [PR 8726](https://www.github.com/boykopovar/AnyPS5/pull/8726) | `docs/dev/debt/libkernel.md` | | [PR 9099](https://www.github.com/boykopovar/AnyPS5/pull/9099) | `docs/dev/debt/libkernel.md` | | [PR 9137](https://www.github.com/boykopovar/AnyPS5/pull/9137) | `docs/dev/debt/libkernel.md` |
xXPBSXx commented 2026-10-20 21:25:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T21:25:56Z.


Thanks @MarcZX10: added the IPv6 case in f6d8cca311. After connect(AF_UNSPEC) on an AF_INET6 socket bound to ::1, getsockname keeps the port and reports ::; the test skips hosts without IPv6 or ::1. With only the IPv6 branch of the fix removed, guest_udp fails on Windows; with it, it passes. Not run on Linux/macOS.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6301832953 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8682#issuecomment-6301832953). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T21:25:56Z. --- Thanks @MarcZX10: added the IPv6 case in f6d8cca311. After `connect(AF_UNSPEC)` on an AF_INET6 socket bound to `::1`, `getsockname` keeps the port and reports `::`; the test skips hosts without IPv6 or `::1`. With only the IPv6 branch of the fix removed, `guest_udp` fails on Windows; with it, it passes. Not run on Linux/macOS. AI-assisted (Claude Code).
MarcZX10 commented 2026-10-20 22:19:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T22:19:17Z.

Review: APPROVED


The current head f6d8cca311 records the cleared local-address state for both IPv4 and IPv6, then reports the wildcard address while preserving the host-assigned port. The new IPv6 regression checks the port and ::, and the author reports Windows failure when only the IPv6 fix is removed and a pass with it. Hosted build/runtime jobs are path-skipped, so I am relying on the reported Windows run; Linux/macOS remain untested. I also left a note about the CMake-style merge-order concern in the UDP implementation: #8344 adds an independent Socket::peer member in the same struct and should be included in the overlap notes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5592503984 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8682#pullrequestreview-5592503984). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T22:19:17Z. **Review:** APPROVED --- The current head `f6d8cca311` records the cleared local-address state for both IPv4 and IPv6, then reports the wildcard address while preserving the host-assigned port. The new IPv6 regression checks the port and `::`, and the author reports Windows failure when only the IPv6 fix is removed and a pass with it. Hosted build/runtime jobs are path-skipped, so I am relying on the reported Windows run; Linux/macOS remain untested. I also left a note about the CMake-style merge-order concern in the UDP implementation: #8344 adds an independent `Socket::peer` member in the same struct and should be included in the overlap notes.
MarcZX10 commented 2026-10-20 22:19:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T22:19:18Z.


One overlap entry appears to be missing from the PR description: the overlap bot flags #8344 on Udp.cpp. I checked that diff; it adds independent Socket::peer tracking for socketpair getpeername, while this PR adds localAddressCleared. There is no behavior duplicate, but the Socket member hunks need to be retained together if both land. Please include #8344 in the manual merge-order notes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6303049236 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8682#issuecomment-6303049236). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T22:19:18Z. --- One overlap entry appears to be missing from the PR description: the overlap bot flags #8344 on `Udp.cpp`. I checked that diff; it adds independent `Socket::peer` tracking for socketpair `getpeername`, while this PR adds `localAddressCleared`. There is no behavior duplicate, but the `Socket` member hunks need to be retained together if both land. Please include #8344 in the manual merge-order notes.
oneandonlydean commented 2026-10-20 23:31:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T23:31:08Z.


@xXPBSXx Thanks. The FreeBSD reference (udp_disconnect resets the local address and keeps the port) is right, and the Windows test coverage is useful.

One concern. When the port is non-zero, Disconnect leaves the host socket bound where it was (e.g. 127.0.0.1:port), and the PR only changes what getsockname reports. After an AF_UNSPEC disconnect, a guest that reads getsockname, sees the wildcard address, and then sendtos a non-loopback destination still gets the host's loopback-bound failure, while getsockname said it could. The project's rule is that a call does what it reports or throws, and a reported state the host doesn't have is harder to diagnose than the current answer.

Two options. (1) Actually move the host socket to the wildcard address: for example, create a new host UDP socket, bind it to wildcard:port, copy the stored options, and swap it in under the socket's lock. (2) If a title needs only the getsockname value, name the title and the call sequence, and keep the debt note explicit that sends still use the old address. Which title reads the local address after dissolving the association?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6304153342 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8682#issuecomment-6304153342). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T23:31:08Z. --- @xXPBSXx Thanks. The FreeBSD reference (`udp_disconnect` resets the local address and keeps the port) is right, and the Windows test coverage is useful. One concern. When the port is non-zero, `Disconnect` leaves the host socket bound where it was (e.g. 127.0.0.1:port), and the PR only changes what `getsockname` reports. After an `AF_UNSPEC` disconnect, a guest that reads `getsockname`, sees the wildcard address, and then `sendto`s a non-loopback destination still gets the host's loopback-bound failure, while `getsockname` said it could. The project's rule is that a call does what it reports or throws, and a reported state the host doesn't have is harder to diagnose than the current answer. Two options. (1) Actually move the host socket to the wildcard address: for example, create a new host UDP socket, bind it to wildcard:port, copy the stored options, and swap it in under the socket's lock. (2) If a title needs only the `getsockname` value, name the title and the call sequence, and keep the debt note explicit that sends still use the old address. Which title reads the local address after dissolving the association?
xXPBSXx commented 2026-10-20 23:55:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T23:55:22Z.


@oneandonlydean you are right, and I measured it before answering. Probe (plain Winsock, Windows 10 Pro 19045, WinLibs GCC 15.2.0): an UDP socket connected to a loopback peer, then connect(AF_UNSPEC), then getsockname, then sendto to this machine's LAN address:

socket before the disconnect host getsockname after it sendto to the LAN address
bound implicitly (the first connect picked the address) 0.0.0.0:<port> succeeds (1 byte)
explicitly bound to 127.0.0.1 127.0.0.1:<port> fails, WSAENETUNREACH (10051)

So the masking only changes the answer for the explicitly bound case, and there it reports a state the host does not have: exactly the failure mode you describe. (The implicit case already reports the wildcard address on main.)

Which title reads the local address after dissolving the association? I do not know of one. I found this by comparing against in_pcbdisconnect, not from a title run, and I cannot name a title or call sequence. So I will not claim option 2.

Option 1 is not something I want to land blind. The host handle in Socket::value is read without a lock in about 50 places (recv, poll, send), and the socket options are set directly on the native handle, so a new socket would need every option the guest set replayed (broadcast, buffer sizes, multicast memberships, TTL/TOS, nonblocking) and a bind of the same port while the old socket still owns it. A guest thread blocked in recvfrom on the old handle would also fail. That is a much larger change than this PR, with no title behind it.

Proposal: I close this PR rather than leave a reported state without a host counterpart. If you prefer to keep a record, I can open a docs-only PR that adds the divergence to the libkernel debt file (after AF_UNSPEC, an explicitly bound UDP socket keeps its bound address; FreeBSD resets it to the wildcard), with the table above as evidence. Tell me which one you want, or if you want option 1 anyway I will do it as a separate PR with a sendto non-loopback test.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6304478000 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8682#issuecomment-6304478000). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T23:55:22Z. --- @oneandonlydean you are right, and I measured it before answering. Probe (plain Winsock, Windows 10 Pro 19045, WinLibs GCC 15.2.0): an UDP socket `connect`ed to a loopback peer, then `connect(AF_UNSPEC)`, then `getsockname`, then `sendto` to this machine's LAN address: | socket before the disconnect | host `getsockname` after it | `sendto` to the LAN address | |---|---|---| | bound implicitly (the first `connect` picked the address) | `0.0.0.0:<port>` | succeeds (1 byte) | | explicitly bound to `127.0.0.1` | `127.0.0.1:<port>` | fails, WSAENETUNREACH (10051) | So the masking only changes the answer for the explicitly bound case, and there it reports a state the host does not have: exactly the failure mode you describe. (The implicit case already reports the wildcard address on `main`.) Which title reads the local address after dissolving the association? I do not know of one. I found this by comparing against `in_pcbdisconnect`, not from a title run, and I cannot name a title or call sequence. So I will not claim option 2. Option 1 is not something I want to land blind. The host handle in `Socket::value` is read without a lock in about 50 places (recv, poll, send), and the socket options are set directly on the native handle, so a new socket would need every option the guest set replayed (broadcast, buffer sizes, multicast memberships, TTL/TOS, nonblocking) and a bind of the same port while the old socket still owns it. A guest thread blocked in `recvfrom` on the old handle would also fail. That is a much larger change than this PR, with no title behind it. Proposal: I close this PR rather than leave a reported state without a host counterpart. If you prefer to keep a record, I can open a docs-only PR that adds the divergence to the libkernel debt file (after `AF_UNSPEC`, an explicitly bound UDP socket keeps its bound address; FreeBSD resets it to the wildcard), with the table above as evidence. Tell me which one you want, or if you want option 1 anyway I will do it as a separate PR with a `sendto` non-loopback test. AI-assisted (Claude Code).
xXPBSXx commented 2026-10-21 00:51:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T00:51:48Z.


Two corrections to my reply above:

  • The reset of the local address to the wildcard is in FreeBSD 11.4's udp_disconnect (udp_usrreq.c), not in in_pcbdisconnect (which only clears the foreign address and port). I named the wrong function.
  • The first row of the table (implicitly bound socket) is what the host's Winsock reports in the probe, not a run of main; only the explicitly bound row is the case this PR changes. I will attach the probe output as a log from a fresh run and correct the table if it differs.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6305236126 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8682#issuecomment-6305236126). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T00:51:48Z. --- Two corrections to my reply above: - The reset of the local address to the wildcard is in FreeBSD 11.4's `udp_disconnect` (`udp_usrreq.c`), not in `in_pcbdisconnect` (which only clears the foreign address and port). I named the wrong function. - The first row of the table (implicitly bound socket) is what the host's Winsock reports in the probe, not a run of `main`; only the explicitly bound row is the case this PR changes. I will attach the probe output as a log from a fresh run and correct the table if it differs. AI-assisted (Claude Code).
oneandonlydean commented 2026-10-21 01:09:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T01:09:34Z.


@xXPBSXx Thanks for measuring it. The table settles it: the masking changes the answer only for the explicitly bound socket, and there the host is still on 127.0.0.1. For an implicitly bound socket, main already passes the host's 0.0.0.0:<port> through getsockname.

So yes, please close this one, and the docs-only PR is welcome. Put it in docs/dev/debt/libkernel.md: after connect(AF_UNSPEC), a UDP socket explicitly bound to an address keeps that address (and getsockname reports it), where FreeBSD's udp_disconnect resets it to the wildcard and keeps the port. Say it was found by comparing against in_pcbdisconnect, not on a title, and link your probe table.

We don't want option 1 without a title: replaying every stored option and swapping the handle under concurrent recvfrom/send is a lot of risk for a value no known title reads. If a title turns up that needs it, the sendto non-loopback test you describe is the right place to start.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6305468502 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8682#issuecomment-6305468502). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T01:09:34Z. --- @xXPBSXx Thanks for measuring it. The table settles it: the masking changes the answer only for the explicitly bound socket, and there the host is still on 127.0.0.1. For an implicitly bound socket, `main` already passes the host's `0.0.0.0:<port>` through `getsockname`. So yes, please close this one, and the docs-only PR is welcome. Put it in `docs/dev/debt/libkernel.md`: after `connect(AF_UNSPEC)`, a UDP socket explicitly bound to an address keeps that address (and `getsockname` reports it), where FreeBSD's `udp_disconnect` resets it to the wildcard and keeps the port. Say it was found by comparing against `in_pcbdisconnect`, not on a title, and link your probe table. We don't want option 1 without a title: replaying every stored option and swapping the handle under concurrent `recvfrom`/`send` is a lot of risk for a value no known title reads. If a title turns up that needs it, the `sendto` non-loopback test you describe is the right place to start.
adriadam10 commented 2026-10-21 18:05:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T18:05:25Z.


Closing as agreed with @oneandonlydean above: the PR makes getsockname report the wildcard address after connect(AF_UNSPEC) on an explicitly bound UDP socket, but the host socket stays bound to that address, so a reported state has no host counterpart and no known title needs it. Swapping the host handle is too risky without a title.

A docs-only PR is welcome: add to docs/dev/debt/libkernel.md that after connect(AF_UNSPEC) an explicitly bound UDP socket keeps its address (and getsockname reports it), where FreeBSD's udp_disconnect resets it to the wildcard and keeps the port, found by comparing against FreeBSD and not on a title, with the probe table linked. Feel free to reopen if a title turns up that needs it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6323020581 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8682#issuecomment-6323020581). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-21T18:05:25Z. --- Closing as agreed with @oneandonlydean above: the PR makes `getsockname` report the wildcard address after `connect(AF_UNSPEC)` on an explicitly bound UDP socket, but the host socket stays bound to that address, so a reported state has no host counterpart and no known title needs it. Swapping the host handle is too risky without a title. A docs-only PR is welcome: add to `docs/dev/debt/libkernel.md` that after `connect(AF_UNSPEC)` an explicitly bound UDP socket keeps its address (and `getsockname` reports it), where FreeBSD's `udp_disconnect` resets it to the wildcard and keeps the port, found by comparing against FreeBSD and not on a title, with the probe table linked. Feel free to reopen if a title turns up that needs it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
boykopovar/AnyPS5!8682
No description provided.