fix(libSceNetCtl): answer sceNetCtlGetInfo from the host IPv4 interface #5056

Merged
0xRickx merged 1 commit from upstream-pr/5056 into main 2026-10-14 18:32:46 +00:00
0xRickx commented 2026-10-13 10:01:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by 0xRickx on 2026-10-13T10:01:44Z.


What

sceNetCtlGetState reports IPOBTAINED when the host has an address, but sceNetCtlGetInfo returned SCE_NET_CTL_ERROR_NOT_CONNECTED for every code. A title that saw a connected console and then asked for its address, netmask or MTU got an error back.

Prospero Explorer (PPSA99109) shows this on main. Its System information > Network tab (DashboardScreen.cs) reads State connected, then - for Address, Subnet mask, Gateway, Primary name server and Hardware address, and 0 bytes for Largest packet (#5071).

PS5VR (PPSA99177) also builds the link under its QR code from code 14 (vr_sources.cpp), but it does not reach that screen yet.

sceNetCtlGetInfo now answers from the host interface that holds an IPv4 address, preferring the one that carries the default route:

  • On Windows, an up adapter with an IPv4 gateway and the lowest interface metric.
  • On Linux, the interface of the lowest-metric default route in /proc/net/route.
Code Answer
14 IP_ADDRESS, 15 NETMASK, 16 DEFAULT_ROUTE, 3 MTU the interface's
17 PRIMARY_DNS, 18 SECONDARY_DNS the interface's first two IPv4 DNS servers (Windows adapter list, Linux /etc/resolv.conf)
1 DEVICE, 4 LINK, 11 IP_CONFIG, 19 HTTP_PROXY_CONFIG wired, connected, DHCP, off
2 ETHER_ADDR 02:50:53:35:00:01, the address sceNetGetMacAddress already reports
5-10 (Wi-Fi), 12 (DHCP host name), 13 (PPPoE user name), 20-21 (proxy server and port) throw
  • Where the codes, layout and error codes come from:
    • Codes 1-21 and the 256-byte union: shadPS4 netctl.h and onionHEN's PS5 net_ctl.h.
    • Only the requested member, at offset 0, is written; the rest of the union is left as it was. SharpProspero NetCtl.cs documents this.
    • A null info returns SCE_NET_CTL_ERROR_INVALID_ADDR (0x80412107). A code outside 1..21 returns SCE_NET_CTL_ERROR_INVALID_CODE (0x80412106, from EA DirtySDK's PS4 error table dirtyerrps4.c), checked in the same order as KytyPS5.
    • With no IPv4 address it returns NOT_CONNECTED, as before.
  • Fixed answers for the guest's link: the guest has no radio, DHCP lease or proxy of its own, so its link is presented as wired, DHCP and without a proxy.
    • The codes that throw are the ones that only mean something on Wi-Fi, PPPoE or a proxy. What a console answers for them is not established.
    • Before this change they returned NOT_CONNECTED.
  • Codes middleware asks for: EA's DirtySDK asks for IP_CONFIG, DEVICE and IP_ADDRESS (netconnps4.cpp, dirtynetps4.c), so all three are answered rather than thrown.
  • Unchanged here: sceNetCtlGetState and sceNetCtlGetIfStat still count IPv6 addresses. On a host with only IPv6, GetState reports IPOBTAINED while GetInfo returns NOT_CONNECTED.

The fixed answers and the 0.0.0.0 used for a missing gateway or DNS server are listed in docs/dev/debt/libSceNetCtl.md.

Tested

Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, main bb9a4d8a (rebased onto 77b9f727 afterwards, no conflicts):

  • New guest_net_ctl test:

    • checks the argument errors;
    • checks the fixed answers, the Ethernet address and that only the member is written;
    • checks the MTU range, a contiguous netmask, and that the reported address binds a UDP socket on this host;
    • checks that the codes that are not answered throw.

    It aborts on main and passes with the change.

  • Both platforms report the same values as the host tools:

    • Windows reports the values ipconfig shows for the adapter with the default route, and skips a VirtualBox host-only adapter.
    • Linux reports eth0 from the default route and skips three docker bridges.
  • guest_sce_net and patched_libraries pass. Full ctest: 1052/1052 passed (8 skipped on this machine).

  • Prospero Explorer (PPSA99109, catalog 01.000.000), relinked, opened on System information > Network with APS5_PAD_INPUT_FILE (steps in #5071) and captured with APS5_DUMP_FRAMES:

    Row main ae244d52 with this change
    State, Link connected, wired connected, wired
    Address - 192.168.178.22
    Subnet mask - 255.255.255.0
    Gateway, Primary name server - 192.168.178.1
    Hardware address - 02:50:53:35:00:01
    Largest packet 0 bytes 1500 bytes

    The host's ipconfig shows the same address, mask, gateway and DNS server.

  • ProsperoLichess (PPSA99009, catalog 01.000.000), relinked with this main, logs [PCH] lan ip 192.168.178.22 with and without the change. When sceNetCtlGetInfo fails it falls back to a connected UDP socket's local address, so the answers agree.

  • tools/check_conventions.py --base upstream/main passes.

Rebased onto main ffa2a6ec without conflicts (head 3065b892), then tested again on main c496fd53:

  • Windows (same toolchain), with my eight other open PRs merged as well: guest_net_ctl, guest_sce_net and patched_libraries pass. Full ctest: 1088/1088 passed (8 skipped on this machine).
  • Linux (Ubuntu 24.04 in WSL, GCC 13.3, Release, the CI's configure options, lavapipe):
    • this branch alone: guest_net_ctl, guest_sce_net and patched_libraries pass.
    • full ctest with my eight other open PRs merged as well: 1067/1070 passed. guest_math, agc_driver_depth_compare_copy and guest_socket_read_write fail the same way on main b8683834 without any of them in this setup.

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: none
  • Unblocks: PPSA99109 #5071
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4841559447 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5056). Originally posted by [0xRickx](https://github.com/0xRickx) on 2026-10-13T10:01:44Z. --- ### What `sceNetCtlGetState` reports `IPOBTAINED` when the host has an address, but `sceNetCtlGetInfo` returned `SCE_NET_CTL_ERROR_NOT_CONNECTED` for every code. A title that saw a connected console and then asked for its address, netmask or MTU got an error back. Prospero Explorer (PPSA99109) shows this on `main`. Its System information > Network tab ([`DashboardScreen.cs`](https://github.com/SvenGDK/Prospero-Explorer/blob/7e8e5d9fdb8d058ba58d48bde96808bf5f4d2408/src/Dashboard/DashboardScreen.cs#L404-L425)) reads State `connected`, then `-` for Address, Subnet mask, Gateway, Primary name server and Hardware address, and `0 bytes` for Largest packet (#5071). PS5VR (PPSA99177) also builds the link under its QR code from code 14 ([`vr_sources.cpp`](https://github.com/theghostonline/PS5VR/blob/0e408909ce7a39891a2e06eee3438d07a09e11e3/app/src/vr_sources.cpp#L793-L804)), but it does not reach that screen yet. `sceNetCtlGetInfo` now answers from the host interface that holds an IPv4 address, preferring the one that carries the default route: - On Windows, an up adapter with an IPv4 gateway and the lowest interface metric. - On Linux, the interface of the lowest-metric default route in `/proc/net/route`. | Code | Answer | | - | - | | 14 `IP_ADDRESS`, 15 `NETMASK`, 16 `DEFAULT_ROUTE`, 3 `MTU` | the interface's | | 17 `PRIMARY_DNS`, 18 `SECONDARY_DNS` | the interface's first two IPv4 DNS servers (Windows adapter list, Linux `/etc/resolv.conf`) | | 1 `DEVICE`, 4 `LINK`, 11 `IP_CONFIG`, 19 `HTTP_PROXY_CONFIG` | wired, connected, DHCP, off | | 2 `ETHER_ADDR` | 02:50:53:35:00:01, the address `sceNetGetMacAddress` already reports | | 5-10 (Wi-Fi), 12 (DHCP host name), 13 (PPPoE user name), 20-21 (proxy server and port) | throw | - **Where the codes, layout and error codes come from:** - Codes 1-21 and the 256-byte union: [shadPS4 `netctl.h`](https://github.com/shadps4-emu/shadPS4/blob/041ba9975ea2f65eb4802bd749e8907821382db2/src/core/libraries/network/netctl.h) and onionHEN's PS5 [`net_ctl.h`](https://github.com/aydencharles/onionHEN/blob/2df9e0b2fbca3b6977edcf3cc53a00a4a77a40f0/source/include/ps5/net_ctl.h). - Only the requested member, at offset 0, is written; the rest of the union is left as it was. [SharpProspero `NetCtl.cs`](https://github.com/SvenGDK/SharpProspero/blob/60977b29103452b9681ae10c7a9011d44965bf16/src/SharpProspero/Interop/Net/NetCtl.cs) documents this. - A null `info` returns `SCE_NET_CTL_ERROR_INVALID_ADDR` (0x80412107). A code outside 1..21 returns `SCE_NET_CTL_ERROR_INVALID_CODE` (0x80412106, from EA DirtySDK's PS4 error table [`dirtyerrps4.c`](https://github.com/TornadoCookie/EAWebKit16-Linux/blob/512af3742d2ca087b4981156275c7d210ea502f1/EAWebKitSupportPackages/DirtySDK/local_15.1.6.0.5/source/dirtysock/ps4/dirtyerrps4.c#L396)), checked in the same order as [KytyPS5](https://github.com/KytyPS5/KytyPS5/blob/e699a35f20bcf790366e73ce6573d04a3e0a789f/src/libs/network.cpp). - With no IPv4 address it returns `NOT_CONNECTED`, as before. - **Fixed answers for the guest's link:** the guest has no radio, DHCP lease or proxy of its own, so its link is presented as wired, DHCP and without a proxy. - The codes that throw are the ones that only mean something on Wi-Fi, PPPoE or a proxy. What a console answers for them is not established. - Before this change they returned `NOT_CONNECTED`. - **Codes middleware asks for:** EA's DirtySDK asks for `IP_CONFIG`, `DEVICE` and `IP_ADDRESS` ([`netconnps4.cpp`](https://github.com/TornadoCookie/EAWebKit16-Linux/blob/512af3742d2ca087b4981156275c7d210ea502f1/EAWebKitSupportPackages/DirtySDK/local_15.1.6.0.5/source/dirtysock/ps4/netconnps4.cpp#L1383-L1410), `dirtynetps4.c`), so all three are answered rather than thrown. - **Unchanged here:** `sceNetCtlGetState` and `sceNetCtlGetIfStat` still count IPv6 addresses. On a host with only IPv6, `GetState` reports `IPOBTAINED` while `GetInfo` returns `NOT_CONNECTED`. The fixed answers and the `0.0.0.0` used for a missing gateway or DNS server are listed in `docs/dev/debt/libSceNetCtl.md`. ### Tested Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, `main` bb9a4d8a (rebased onto 77b9f727 afterwards, no conflicts): - New `guest_net_ctl` test: - checks the argument errors; - checks the fixed answers, the Ethernet address and that only the member is written; - checks the MTU range, a contiguous netmask, and that the reported address binds a UDP socket on this host; - checks that the codes that are not answered throw. It aborts on `main` and passes with the change. - Both platforms report the same values as the host tools: - Windows reports the values `ipconfig` shows for the adapter with the default route, and skips a VirtualBox host-only adapter. - Linux reports `eth0` from the default route and skips three docker bridges. - `guest_sce_net` and `patched_libraries` pass. Full ctest: 1052/1052 passed (8 skipped on this machine). - Prospero Explorer (PPSA99109, catalog 01.000.000), relinked, opened on System information > Network with `APS5_PAD_INPUT_FILE` (steps in #5071) and captured with `APS5_DUMP_FRAMES`: | Row | `main` ae244d52 | with this change | | - | - | - | | State, Link | connected, wired | connected, wired | | Address | - | 192.168.178.22 | | Subnet mask | - | 255.255.255.0 | | Gateway, Primary name server | - | 192.168.178.1 | | Hardware address | - | 02:50:53:35:00:01 | | Largest packet | 0 bytes | 1500 bytes | The host's `ipconfig` shows the same address, mask, gateway and DNS server. - ProsperoLichess (PPSA99009, catalog 01.000.000), relinked with this `main`, logs `[PCH] lan ip 192.168.178.22` with and without the change. When `sceNetCtlGetInfo` fails it falls back to a connected UDP socket's local address, so the answers agree. - `tools/check_conventions.py --base upstream/main` passes. Rebased onto `main` ffa2a6ec without conflicts (head 3065b892), then tested again on `main` c496fd53: - Windows (same toolchain), with my eight other open PRs merged as well: `guest_net_ctl`, `guest_sce_net` and `patched_libraries` pass. Full ctest: 1088/1088 passed (8 skipped on this machine). - Linux (Ubuntu 24.04 in WSL, GCC 13.3, Release, the CI's configure options, lavapipe): - this branch alone: `guest_net_ctl`, `guest_sce_net` and `patched_libraries` pass. - full ctest with my eight other open PRs merged as well: 1067/1070 passed. `guest_math`, `agc_driver_depth_compare_copy` and `guest_socket_read_write` fail the same way on `main` b8683834 without any of them in this setup. ### 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](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: none - [x] Unblocks: PPSA99109 #5071 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
adriadam10 commented 2026-10-14 17:37:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:37:43Z.


Checked the build and ctest (guest_net_ctl passes, and fails without the change), the argument errors and code ranges against KytyPS5 and shadPS4, and the test registration and debt entry; merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6174467277 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5056#issuecomment-6174467277). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T17:37:43Z. --- Checked the build and ctest (`guest_net_ctl` passes, and fails without the change), the argument errors and code ranges against KytyPS5 and shadPS4, and the test registration and debt entry; merging once the full Build is green.
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!5056
No description provided.