fix(libSceNet): ignore IPv4-mapped results of an IPv6 name lookup on macOS #10629

Merged
maximilianfv merged 1 commit from upstream-pr/10629 into main 2026-11-08 05:44:16 +00:00
maximilianfv commented 2026-10-24 13:32:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by maximilianfv on 2026-10-24T13:32:58Z.


What

On macOS, getaddrinfo with ai_family = AF_INET6 and no flags answers an IPv4 literal such as "127.0.0.1" with the IPv4-mapped address ::ffff:127.0.0.1. lookup_host passes that on, so sceNetResolverStartNtoa6(resolver, "127.0.0.1", ...) returns 0 and writes ::ffff:127.0.0.1. guest_sce_net expects SCE_NET_ERROR_RESOLVER_ENODNS (0x804101E1) with the output buffer unchanged (core/libs/tests/GuestSceNet.cpp:2381), and the sceNetResolverStartNtoa6 entry in docs/dev/debt/libSceNet.md says a name with no IPv6 address fails with RESOLVER_ENODNS.

FreeBSD 11.4's getaddrinfo returns no IPv4-mapped address for an AF_INET6 query unless AI_V4MAPPED is set: an IPv4 literal is accepted only with that flag (explore_numeric), and DNS asks for A records only with that flag (_dns_getaddrinfo). lookup_host never sets it.

This PR makes lookup_host skip IPv4-mapped results of an AF_INET6 lookup on macOS (IN6_IS_ADDR_V4MAPPED). sceNetResolverStartNtoa6 is the only AF_INET6 caller of lookup_host. Linux and Windows are unchanged.

A small host probe (getaddrinfo, AF_INET6, flags 0) on macOS returned ::ffff:127.0.0.1 for "127.0.0.1", ::1 for "::1" and ::1 for "localhost".

Limitations, on macOS only:

  • An AAAA record whose value is itself an IPv4-mapped address is now skipped. FreeBSD 11.4 returns it: the filter for such records is behind FILTER_V4MAPPED, which its libc Makefiles do not define.
  • A name with only A records, looked up as AF_INET6, now fails with RESOLVER_ENODNS as on FreeBSD (only an IPv4 literal was probed on macOS, not a real A-only name).

Prior art: the same change was written before in two whole-port PRs that are now closed, so both authors are credited as co-authors on the commit. #7332 by Ycaro Gabriel (ycarogabriel-lgtm) has identical code in commit a8fa3e9008 (2026-10-17). #8658 by Himansh Raj (iamthehimansh) has identical code plus a comment in commit 301073a29e (2026-10-19). #7201 by marion909 (commit c31e82f31f, 2026-10-16, closed 2026-10-27) took a different approach for the same test: on macOS, an AF_INET6 lookup of a name that parses as an IPv4 literal fails before getaddrinfo runs. That approach does not cover A-only names. No open PR changes lookup_host.

Tested

Apple M1 Pro, macOS 27.0.1, x86_64 build under Rosetta 2.

main alone does not build on macOS, so I tested in a tree made of mugurc's macOS series (ci/macos-series-2, 27e968974) merged with main at 1e20650e84, open #9231 (7c5d97324) and my own sceNetIoctl FIONREAD fix (not yet opened). Only this change was toggled between runs. These runs are from before the 2026-10-27 rebase onto main at 3bed136010; the rebase changed only context lines of this diff, and I have not rerun them on it.

  • ctest -R '^(guest_sce_net|guest_resolver|guest_net_ctl|guest_inet_address|guest_net_.*|guest_datagram_.*|net_dontwait_.*|guest_socket_error|guest_udp)$' (22 tests): 21 pass with and without the change.
  • guest_sce_net aborts with and without the change. Without the change it stops at the check above (GuestSceNet.cpp:1932 on 1e20650e84, now :2381, located with lldb on an -O0 rebuild). With the change it passes that check and stops later, at the sceNetCtlGetIfStat(&first) call (GuestSceNet.cpp:2168 on 1e20650e84, now :2615). That stop is an uncaught "sceNetCtlGetIfStat: host interface byte counters are not implemented on this platform" (libSceNetCtl/Export.cpp:511 on 1e20650e84, now :868), a separate macOS gap that open #9728 (MarcZX10) closes.

Not tested on Linux or Windows. Their code is unchanged.

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 (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #10502 (GuestSceNet.cpp and neighbouring docs/dev/debt/libSceNet.md entries; I rebase this one after it). #9727 and #9733 are merged; #7201 is closed
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4995820514 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10629). Originally posted by [maximilianfv](https://github.com/maximilianfv) on 2026-10-24T13:32:58Z. --- ### What On macOS, `getaddrinfo` with `ai_family = AF_INET6` and no flags answers an IPv4 literal such as `"127.0.0.1"` with the IPv4-mapped address `::ffff:127.0.0.1`. `lookup_host` passes that on, so `sceNetResolverStartNtoa6(resolver, "127.0.0.1", ...)` returns 0 and writes `::ffff:127.0.0.1`. `guest_sce_net` expects `SCE_NET_ERROR_RESOLVER_ENODNS` (`0x804101E1`) with the output buffer unchanged (`core/libs/tests/GuestSceNet.cpp:2381`), and the `sceNetResolverStartNtoa6` entry in `docs/dev/debt/libSceNet.md` says a name with no IPv6 address fails with `RESOLVER_ENODNS`. FreeBSD 11.4's `getaddrinfo` returns no IPv4-mapped address for an `AF_INET6` query unless `AI_V4MAPPED` is set: an IPv4 literal is accepted only with that flag ([`explore_numeric`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/libc/net/getaddrinfo.c#L1284-L1296)), and DNS asks for A records only with that flag ([`_dns_getaddrinfo`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/libc/net/getaddrinfo.c#L2291-L2296)). `lookup_host` never sets it. This PR makes `lookup_host` skip IPv4-mapped results of an `AF_INET6` lookup on macOS (`IN6_IS_ADDR_V4MAPPED`). `sceNetResolverStartNtoa6` is the only `AF_INET6` caller of `lookup_host`. Linux and Windows are unchanged. A small host probe (`getaddrinfo`, `AF_INET6`, flags 0) on macOS returned `::ffff:127.0.0.1` for `"127.0.0.1"`, `::1` for `"::1"` and `::1` for `"localhost"`. Limitations, on macOS only: - An AAAA record whose value is itself an IPv4-mapped address is now skipped. FreeBSD 11.4 returns it: the filter for such records is behind `FILTER_V4MAPPED`, which its libc Makefiles do not define. - A name with only A records, looked up as `AF_INET6`, now fails with `RESOLVER_ENODNS` as on FreeBSD (only an IPv4 literal was probed on macOS, not a real A-only name). Prior art: the same change was written before in two whole-port PRs that are now closed, so both authors are credited as co-authors on the commit. #7332 by Ycaro Gabriel (ycarogabriel-lgtm) has identical code in commit a8fa3e9008 (2026-10-17). #8658 by Himansh Raj (iamthehimansh) has identical code plus a comment in commit 301073a29e (2026-10-19). #7201 by marion909 (commit c31e82f31f, 2026-10-16, closed 2026-10-27) took a different approach for the same test: on macOS, an `AF_INET6` lookup of a name that parses as an IPv4 literal fails before `getaddrinfo` runs. That approach does not cover A-only names. No open PR changes `lookup_host`. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Apple M1 Pro, macOS 27.0.1, x86_64 build under Rosetta 2. `main` alone does not build on macOS, so I tested in a tree made of mugurc's macOS series (`ci/macos-series-2`, `27e968974`) merged with `main` at `1e20650e84`, open #9231 (`7c5d97324`) and my own sceNetIoctl `FIONREAD` fix (not yet opened). Only this change was toggled between runs. These runs are from before the 2026-10-27 rebase onto `main` at `3bed136010`; the rebase changed only context lines of this diff, and I have not rerun them on it. - `ctest -R '^(guest_sce_net|guest_resolver|guest_net_ctl|guest_inet_address|guest_net_.*|guest_datagram_.*|net_dontwait_.*|guest_socket_error|guest_udp)$'` (22 tests): 21 pass with and without the change. - `guest_sce_net` aborts with and without the change. Without the change it stops at the check above (`GuestSceNet.cpp:1932` on `1e20650e84`, now `:2381`, located with lldb on an `-O0` rebuild). With the change it passes that check and stops later, at the `sceNetCtlGetIfStat(&first)` call (`GuestSceNet.cpp:2168` on `1e20650e84`, now `:2615`). That stop is an uncaught "sceNetCtlGetIfStat: host interface byte counters are not implemented on this platform" (`libSceNetCtl/Export.cpp:511` on `1e20650e84`, now `:868`), a separate macOS gap that open #9728 (MarcZX10) closes. Not tested on Linux or Windows. Their code is unchanged. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> #10502 (`GuestSceNet.cpp` and neighbouring `docs/dev/debt/libSceNet.md` entries; I rebase this one after it). #9727 and #9733 are merged; #7201 is closed - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-24 13:40:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T13:40:41Z.

Review: COMMENTED


The PR body identifies overlapping lookup_host behavior in open #7201 but the checklist still says Depends on: none. CONTRIBUTING requires the authors to agree on merge order and record the dependency. I left the specific request in this comment; no author response or body update is present at this head. I have not approved pending that coordination.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638445815 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10629#pullrequestreview-5638445815). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T13:40:41Z. **Review:** COMMENTED --- The PR body identifies overlapping `lookup_host` behavior in open #7201 but the checklist still says `Depends on: none`. CONTRIBUTING requires the authors to agree on merge order and record the dependency. I left the specific request in [this comment](https://github.com/boykopovar/AnyPS5/pull/10629#issuecomment-6384874005); no author response or body update is present at this head. I have not approved pending that coordination.
MarcZX10 commented 2026-10-24 13:52:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T13:52:04Z.

Review: CHANGES_REQUESTED


Follow-up on the current overlap warnings at head b5868dd32860621102859b462b6cc0486794994a. Manual checks confirm two coordination items beyond the original checklist mismatch:

  • #7201 edits the same lookup_host path on macOS (it rejects numeric IPv4 literals before getaddrinfo; this PR filters IPv4-mapped results). git merge-tree --write-tree upstream/pr/7201 upstream/pr/10629 conflicts inside lookup_host, so these behaviors need an agreed order and a combined test/implementation plan. The body mentions #7201 but the checklist still says Depends on: none.
  • #10502 implements sceNetShowIfconfig and sceNetShowNetstat, while this branch's CheckNetstat still expects those calls to throw. The three-way merge conflicts in GuestSceNet.cpp at that test and in the Silent stubs debt entry. Please coordinate order with #10502 and reconcile the test expectations so the combined branch tests the implemented diagnostics rather than treating them as unsupported.

I also confirmed adjacent debt-file conflicts with #9727 and #9733 via merge-tree; their implementation changes are in other functions, but the shared documentation hunks will need to retain both updates. The broad #5836 diff changes peer socket types/options, not lookup_host, so I found no direct resolver implementation overlap there.

Please agree on the merge order with the affected authors and record the required dependency or dependencies in the checklist. I have not run a local macOS resolver test; the PR's host probe and reported platform test remain author evidence.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638482747 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10629#pullrequestreview-5638482747). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T13:52:04Z. **Review:** CHANGES_REQUESTED --- Follow-up on the current overlap warnings at head `b5868dd32860621102859b462b6cc0486794994a`. Manual checks confirm two coordination items beyond the original checklist mismatch: - #7201 edits the same `lookup_host` path on macOS (it rejects numeric IPv4 literals before `getaddrinfo`; this PR filters IPv4-mapped results). `git merge-tree --write-tree upstream/pr/7201 upstream/pr/10629` conflicts inside `lookup_host`, so these behaviors need an agreed order and a combined test/implementation plan. The body mentions #7201 but the checklist still says `Depends on: none`. - #10502 implements `sceNetShowIfconfig` and `sceNetShowNetstat`, while this branch's `CheckNetstat` still expects those calls to throw. The three-way merge conflicts in `GuestSceNet.cpp` at that test and in the `Silent stubs` debt entry. Please coordinate order with #10502 and reconcile the test expectations so the combined branch tests the implemented diagnostics rather than treating them as unsupported. I also confirmed adjacent debt-file conflicts with #9727 and #9733 via merge-tree; their implementation changes are in other functions, but the shared documentation hunks will need to retain both updates. The broad #5836 diff changes peer socket types/options, not `lookup_host`, so I found no direct resolver implementation overlap there. Please agree on the merge order with the affected authors and record the required dependency or dependencies in the checklist. I have not run a local macOS resolver test; the PR's host probe and reported platform test remain author evidence.
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!10629
No description provided.