fix(libkernel): send to INADDR_ANY through 127.0.0.1 on macOS #17878

Merged
Alexius0815 merged 2 commits from upstream-pr/17878 into main 2026-12-04 11:04:02 +00:00
Alexius0815 commented 2026-11-09 20:08:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Alexius0815 on 2026-11-09T20:08:16Z.


What

On macOS, a datagram sent to 0.0.0.0 or ::ffff:0.0.0.0 fails with EHOSTUNREACH (65). This makes guest_socket_port_zero fail. The change applies AnyPS5's existing loopback mapping to these destinations in the Darwin sendto path, matching the mapping used on Windows by #15782.

FreeBSD 11.4's in_pcbconnect_setup selects the first local IPv4 address for an unspecified destination. Loopback is AnyPS5's approximation for this case. The connect path already passes the guest test on macOS and is unchanged.

Tested

Apple M4 (Mac16,13), macOS 27.2, Release x86-64 under Rosetta 2. CTest ran serially with the final v4 diffs on Mac integration stack b05b1c4c93a2 (main 02452319 with Mac build fixes). The review commit is based on main 7259cce111.

  • Baseline: guest_socket_port_zero fails with errno 65.
  • UDP-only arm: guest_socket_port_zero passes. The separate guest_socket_options failure remains.
  • IPv4-only variant: the test still fails for ::ffff:0.0.0.0.
  • Combined UDP and TCP arm: 95 of 97 socket and network tests pass, one is skipped (guest_net_raw_protocol), and guest_sce_net hits the known epoll closed-stream failure.

Checklist

  • Based on current main; no other open PR implements the same change
  • One topic per PR
  • No comments added to source code
  • No new stubs or third-party code
  • No investigation files added to the repository
  • Generic behavior, independent of title
  • Depends on: none
  • Fixes: none
  • Unblocks: none known
  • GPUs tested: n/a
  • AI-assisted: yes

Summary by CodeRabbit

  • Bug Fixes
    • UDP sends to unspecified Internet destinations now apply loopback handling on macOS, matching the existing behavior on Windows. This makes destination handling more consistent across the two platforms when sending UDP traffic to an unspecified address.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5230397662 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17878). Originally posted by [Alexius0815](https://github.com/Alexius0815) on 2026-11-09T20:08:16Z. --- ### What On macOS, a datagram sent to `0.0.0.0` or `::ffff:0.0.0.0` fails with `EHOSTUNREACH` (65). This makes `guest_socket_port_zero` fail. The change applies AnyPS5's existing loopback mapping to these destinations in the Darwin `sendto` path, matching the mapping used on Windows by #15782. FreeBSD 11.4's `in_pcbconnect_setup` selects the first local IPv4 address for an unspecified destination. Loopback is AnyPS5's approximation for this case. The `connect` path already passes the guest test on macOS and is unchanged. ### Tested Apple M4 (Mac16,13), macOS 27.2, Release x86-64 under Rosetta 2. CTest ran serially with the final v4 diffs on Mac integration stack `b05b1c4c93a2` (main `02452319` with Mac build fixes). The review commit is based on main `7259cce111`. - Baseline: `guest_socket_port_zero` fails with errno 65. - UDP-only arm: `guest_socket_port_zero` passes. The separate `guest_socket_options` failure remains. - IPv4-only variant: the test still fails for `::ffff:0.0.0.0`. - Combined UDP and TCP arm: 95 of 97 socket and network tests pass, one is skipped (`guest_net_raw_protocol`), and `guest_sce_net` hits the known epoll closed-stream failure. ### Checklist - [x] Based on current `main`; no other open PR implements the same change - [x] One topic per PR - [x] No comments added to source code - [x] No new stubs or third-party code - [x] No investigation files added to the repository - [x] Generic behavior, independent of title - Depends on: none - Fixes: none - Unblocks: none known - GPUs tested: n/a - AI-assisted: yes <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * UDP sends to unspecified Internet destinations now apply loopback handling on macOS, matching the existing behavior on Windows. This makes destination handling more consistent across the two platforms when sending UDP traffic to an unspecified address. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
kurexw commented 2026-11-16 12:13:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-16T12:13:34Z.

Review: COMMENTED


Tested on macOS 27.2, Apple Silicon (M4), full build (x86-64 under Rosetta 2). This PR was merged alone onto main 04f7633c01 with git merge --no-ff. I ran the 56 socket and net tests (guest_socket_*, guest_poll, guest_refused_connect, guest_sce_net, guest_net_*, guest_kernel_socket*) three times on main and three times with this PR.

  • guest_socket_port_zero fails in all three runs on main ("sendto INADDR_ANY must reach 127.0.0.1 (errno 65)") and passes in all three runs with this PR.
  • No other test changes. In one run, guest_socket_read_write failed with ECONNRESET. That test is flaky on main too (1 failure in 10 runs on main, 0 in 10 with this PR), so this PR is not the cause.
  • This PR and #17879 conflict in core/libs/prx/libkernel/Socket/src/Udp.cpp, so whichever merges second needs a rebase.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5919766494 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17878#pullrequestreview-5919766494). Originally posted by [kurexw](https://github.com/kurexw) on 2026-11-16T12:13:34Z. **Review:** COMMENTED --- Tested on macOS 27.2, Apple Silicon (M4), full build (x86-64 under Rosetta 2). This PR was merged alone onto `main` 04f7633c01 with `git merge --no-ff`. I ran the 56 socket and net tests (`guest_socket_*`, `guest_poll`, `guest_refused_connect`, `guest_sce_net`, `guest_net_*`, `guest_kernel_socket*`) three times on `main` and three times with this PR. - `guest_socket_port_zero` fails in all three runs on `main` ("sendto INADDR_ANY must reach 127.0.0.1 (errno 65)") and passes in all three runs with this PR. - No other test changes. In one run, `guest_socket_read_write` failed with `ECONNRESET`. That test is flaky on `main` too (1 failure in 10 runs on `main`, 0 in 10 with this PR), so this PR is not the cause. - This PR and #17879 conflict in `core/libs/prx/libkernel/Socket/src/Udp.cpp`, so whichever merges second needs a rebase.
MarcZX10 commented 2026-11-21 10:02:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T10:02:24Z.

Review: APPROVED


Reviewed — looks good

The change applies the existing unspecified-address loopback mapping to Darwin sendto and the inspected implementation covers IPv4 and IPv4-mapped IPv6.

What I ran

Reviewed head 0a7cf3a1d353f2c325c9e5d267dae841fde38b6f. No commands or tests were run; the author-reported test results were not independently verified.

Results

Check Result Note
Diff and changed code passed One changed source file read
Tests not run No tests run during review

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports macOS test results in the PR description; they were not independently confirmed. files.json was unavailable in the provided review bundle, so I could not compare the read files against its reviewed list. No test, build, or platform behavior was run. Read: description.md, commits.md, manifest.json, diff.patch, and core/libs/prx/libkernel/Socket/src/Udp.cpp lines 400–460 and 1990–2029. Excluded: no paths were available from files.json.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6004516347 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17878#pullrequestreview-6004516347). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T10:02:24Z. **Review:** APPROVED --- # Reviewed — looks good The change applies the existing unspecified-address loopback mapping to Darwin `sendto` and the inspected implementation covers IPv4 and IPv4-mapped IPv6. ## What I ran Reviewed head `0a7cf3a1d353f2c325c9e5d267dae841fde38b6f`. No commands or tests were run; the author-reported test results were not independently verified. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | One changed source file read | | Tests | not run | No tests run during review | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The author reports macOS test results in the PR description; they were not independently confirmed. `files.json` was unavailable in the provided review bundle, so I could not compare the read files against its reviewed list. No test, build, or platform behavior was run. Read: `description.md`, `commits.md`, `manifest.json`, `diff.patch`, and `core/libs/prx/libkernel/Socket/src/Udp.cpp` lines 400–460 and 1990–2029. Excluded: no paths were available from `files.json`. ## To get this to a good state Nothing is required.
NobleBrains commented 2026-12-01 00:21:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NobleBrains on 2026-12-01T00:21:55Z.

Review: APPROVED


Confirmed on macOS 15.

Setup: Apple M4, macOS 15.7.9, Apple clang 17.0.0 (clang-1700.6.3.2), x86_64 Release under Rosetta, BUILD_TESTING=ON. These are the OS and compiler generation of the macos-15 runner.
Tree: main 93d64f2d1e + the open macOS build fixes #27201, #27739, #27843, #17425, #27827, #27767 (main does not build on macOS without them, see #28168), + #22091, #28369, #28075, #28076, #28284, then #17878, #20161, #25134, #26806, #22932, #28373, #27828, #27950, #27582, #24311 merged one after another. All merged cleanly.

guest_socket_port_zero failures
same tree before this PR 3/3
with this PR at 0a7cf3a1d3 0/5

Full ctest -j 6 after all of them: 7047/7066 pass. Compared with the run before the second group of merges, no test fails that passed before.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6122948587 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17878#pullrequestreview-6122948587). Originally posted by [NobleBrains](https://github.com/NobleBrains) on 2026-12-01T00:21:55Z. **Review:** APPROVED --- Confirmed on macOS 15. **Setup:** Apple M4, macOS 15.7.9, Apple clang 17.0.0 (clang-1700.6.3.2), x86_64 Release under Rosetta, `BUILD_TESTING=ON`. These are the OS and compiler generation of the `macos-15` runner. **Tree:** `main` `93d64f2d1e` + the open macOS build fixes #27201, #27739, #27843, #17425, #27827, #27767 (`main` does not build on macOS without them, see #28168), + #22091, #28369, #28075, #28076, #28284, then #17878, #20161, #25134, #26806, #22932, #28373, #27828, #27950, #27582, #24311 merged one after another. All merged cleanly. | `guest_socket_port_zero` | failures | |---|---| | same tree before this PR | 3/3 | | with this PR at `0a7cf3a1d3` | 0/5 | **Full `ctest -j 6`** after all of them: 7047/7066 pass. Compared with the run before the second group of merges, no test fails that passed before. AI-assisted: yes (Claude Code)
ligmaSec commented 2026-12-03 16:40:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T16:40:36Z.

Review: COMMENTED


The existing guest_socket_port_zero regression passed with this head integrated on Linux. The changed branch reuses the established IPv4 and IPv4-mapped loopback conversion for Darwin sendto. The conversion itself still needs a macOS run.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6174139998 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17878#pullrequestreview-6174139998). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T16:40:36Z. **Review:** COMMENTED --- The existing `guest_socket_port_zero` regression passed with this head integrated on Linux. The changed branch reuses the established IPv4 and IPv4-mapped loopback conversion for Darwin `sendto`. The conversion itself still needs a macOS run. AI-assisted: yes.
MarcZX10 commented 2026-12-04 09:57:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T09:57:02Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this; the points below are optional.

What I ran

Reviewed head 56d2119552631118a9c0ab2bd15d8a4bad1c54d7. I read the prepared description, commits, manifest, diff, and the changed file’s relevant helper, address conversion, sendto, and connect sections with repo_read.py. No tests or builds were run.

Results

Check Result Note
Changed code review passed Mapping is limited to unspecified IPv4 destinations and IPv4-mapped IPv6 destinations.
Tests and build not run The author reports macOS test results; I did not independently verify them.

Negative control

Not run; no test was run.

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

The reported macOS test results and behavior on physical consoles were not independently verified. The reviewed file was core/libs/prx/libkernel/Socket/src/Udp.cpp; files.json lists no excluded files.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6186937655 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17878#pullrequestreview-6186937655). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-12-04T09:57:02Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this; the points below are optional. ## What I ran Reviewed head `56d2119552631118a9c0ab2bd15d8a4bad1c54d7`. I read the prepared description, commits, manifest, diff, and the changed file’s relevant helper, address conversion, sendto, and connect sections with `repo_read.py`. No tests or builds were run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Mapping is limited to unspecified IPv4 destinations and IPv4-mapped IPv6 destinations. | | Tests and build | not run | The author reports macOS test results; I did not independently verify them. | ## Negative control Not run; no test was run. ## Findings ### Blocking None. ### Non-blocking None. ## Sources - [`Udp.cpp` at the reviewed commit](https://github.com/boykopovar/AnyPS5/blob/56d2119552631118a9c0ab2bd15d8a4bad1c54d7/core/libs/prx/libkernel/Socket/src/Udp.cpp#L504-L518) defines the IPv4 and IPv4-mapped IPv6 loopback conversion. - [`Udp.cpp` at the reviewed commit](https://github.com/boykopovar/AnyPS5/blob/56d2119552631118a9c0ab2bd15d8a4bad1c54d7/core/libs/prx/libkernel/Socket/src/Udp.cpp#L2769-L2783) applies it in the Darwin `sendto` path. ## Not verified The reported macOS test results and behavior on physical consoles were not independently verified. The reviewed file was `core/libs/prx/libkernel/Socket/src/Udp.cpp`; `files.json` lists no excluded files. ## To get this to a good state Nothing is required.
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!17878
No description provided.