Skip to content

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

Open
maximilianfv wants to merge 1 commit into
boykopovar:mainfrom
maximilianfv:fix/libscenet-macos-resolver-skip-v4-mapped
Open

maximilianfv wants to merge 1 commit into
boykopovar:mainfrom
maximilianfv:fix/libscenet-macos-resolver-skip-v4-mapped

Conversation

@maximilianfv

@maximilianfv maximilianfv commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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:1932), 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 a8fa3e9 (2026-10-17). #8658 by Himansh Raj (iamthehimansh) has identical code plus a comment in commit 301073a (2026-10-19). Open #7201 by marion909 (commit c31e82f, 2026-10-16) takes 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. Apart from the whole-port #7201, 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.

  • 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 current main, 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 current main). That stop is an uncaught "sceNetCtlGetIfStat: host interface byte counters are not implemented on this platform" (libSceNetCtl/Export.cpp:511), a separate macOS gap that open feat(libSceNetCtl): read macOS interface byte counters #9728 (MarcZX10) closes.

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

Checklist

🤖 Generated with Claude Code

…macOS

macOS getaddrinfo answers an AF_INET6 lookup of an IPv4 address, such
as "127.0.0.1", with the IPv4-mapped address ::ffff:127.0.0.1 even
without AI_V4MAPPED, so sceNetResolverStartNtoa6 succeeded where it
must fail with SCE_NET_ERROR_RESOLVER_ENODNS. FreeBSD returns no mapped
address for an IPv4 literal or an A-only name unless AI_V4MAPPED is
set, which the resolver never sets. Skip IPv4-mapped results of an
AF_INET6 lookup on macOS.

Co-authored-by: Ycaro Gabriel <280482597+ycarogabriel-lgtm@users.noreply.github.com>
Co-authored-by: Himansh Raj <67262056+iamthehimansh@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MarcZX10

Copy link
Copy Markdown
Contributor

The prior-art section says #7201 remains open and makes a whole-port change that overlaps the same lookup_host behavior, but this PR's checklist says Depends on: none. CONTRIBUTING.md says the PR overlap comment identifies open PRs that change the same lines or exports; the authors should agree which goes first and declare it with Depends on. Please coordinate with #7201's author and record the agreed order (or explain why this exact overlap does not require one) before merging. I have not independently run the macOS behavior probe; the stated host probe and targeted regression evidence are useful.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

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 11155 docs/dev/debt/libSceNet.md L63-64

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 5836 core/libs/prx/libSceNet/Export.cpp
docs/dev/debt/libSceNet.md
PR 7201 core/libs/prx/libSceNet/Export.cpp
PR 9932 core/libs/prx/libSceNet/Export.cpp
docs/dev/debt/libSceNet.md
PR 9948 core/libs/prx/libSceNet/Export.cpp
docs/dev/debt/libSceNet.md
PR 11341 core/libs/prx/libSceNet/Export.cpp

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@maximilianfv maximilianfv mentioned this pull request Oct 24, 2026
8 of 11 tasks
@maximilianfv

Copy link
Copy Markdown
Contributor Author

Thanks. The checklist now has Depends on: #10502, #9727 and #9733: this PR waits for them and I rebase it afterwards, keeping their entries and #10502's implemented CheckNetstat expectations. For lookup_host I asked marion909 about the order with #7201 (link in the checklist).

AI-assisted: yes

@Gonic0

Gonic0 commented Oct 24, 2026

Copy link
Copy Markdown

On the limitation you list about A-only names: I probed it on an M5 Pro, macOS 27.2 (26B5086k), built both x86_64 (Rosetta 2) and arm64. Both builds give the same results. The network is dual-stack with global IPv6 and no DNS64. getaddrinfo with AF_INET6:

Name flags 0 AI_V4MAPPED
127.0.0.1 ::ffff:127.0.0.1 same
::1 ::1 same
localhost ::1 same
ipv4only.arpa (A only, RFC 7050) ::ffff:192.0.0.170, ::ffff:192.0.0.171 same
github.com (A only) ::ffff:140.82.114.3 same

So a real A-only name is mapped on macOS too, even with flags 0, and with this change it fails with RESOLVER_ENODNS as on FreeBSD. AI_V4MAPPED makes no difference here, so macOS can't be steered out of mapping by flags; filtering the results is the only way.

libSceNet/Export.cpp at b5868dd328 also compiles here (Apple clang 21.0.0, x86_64 Release), with no warnings in the changed lines under -Wall -Wextra. I didn't run guest_sce_net.

AI-assisted: yes

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants