fix(libSceNet): print the interface and socket tables from sceNetShowIfconfig and sceNetShowNetstat #10502

Merged
frankea merged 1 commit from upstream-pr/10502 into main 2026-10-28 08:49:52 +00:00
frankea commented 2026-10-24 05:04:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-24T05:04:02Z.


What

Since #9137 (04f2d9a60), sceNetShowIfconfig and sceNetShowNetstat throw once sceNetInit has run (Initialized calls throw because native diagnostic collection and formatting are not implemented), so a title that calls either for its log stops there. On a PS5 both return 0 and print plain-text tables to the caller's stdout. They now do the same, in the console's layout, with what the emulator knows. Before initialization both still return the not-initialized error.

sceNetShowIfconfig:

  • An eth0 (index=1) block when sceNetCtlGetInfo has a host IPv4 interface to report, with the same values a title reads there: the MAC 02:50:53:35:00:01 (also sceNetGetMacAddress's), the address, the netmask, the broadcast address derived from them and the MTU. The interface comes from a new NetCtlHostIpv4Address_nid_no_patch, next to the existing NetCtlHostDnsServers_nid_no_patch.
  • The console's lo0 (index=2) block as it printed it.
  • dns addresses with the two IPv4 servers sceNetGetDnsInfo returns, and ::, :: for IPv6.

sceNetShowNetstat:

  • The console's header, --- ID, type, [self/R/S/RE/SE//NB], ... ---, then one entry per socket (UDP, then TCP, then raw, as the console groups them, each by descending ID) and one line per epoll.
  • Each socket entry has the console's five lines: the ID, type, flags with self set and NB from SO_NBIO, the state (OPENED for UDP and raw; LISTEN, ESTABLISHED or CLOSED for TCP), the title's pid and the name; the local and remote address (* for the IPv4 wildcard and [*] for IPv6's, as the console writes them, * for port 0, and 28 trailing spaces, as the console pads them); and the send and receive buffer sizes sceNetGetsockopt reports.
  • The names given to sceNetSocket and sceNetEpollCreate were ignored. They are now kept, cut to 31 characters (the 32-byte name of SceNetSockInfo), for these lines.

Left out, in the debt entry: ifconfig's IPv6 address, UP6, link status, traffic counters and times for eth0, the wireless interfaces, and the pool and statistics sections. Netstat lists only the title's own sockets and epolls, while the console lists every process's. The R, S, RE and SE flags, the field after the type, the queue lengths, rates and drop counts print as on an idle console socket, and the self flag on epoll lines is inferred from the socket lines. sceNetShowNetstatWithMemory keeps its existing output.

Measurement: PS5 on firmware 13.40, 2026-10-19, from an elfldr payload process that called both after sceNetInit. Both returned 0. Ifconfig printed eth0, lo0, wlan0 and wlan1 blocks, then the DNS, pool and statistics sections. Netstat printed the header and an entry for every socket and epoll of every process, for example:

ID:   15 (  tcp,  0) ...*.-* ESTABLISHED pid=0x00000056 
  Local : 127.0.0.1:8084                            
  Remote: 127.0.0.1:59637                            
  Send-Q: 0/49032 TX: 0bps/0bps, dropped 0 (0) 
  Recv-Q: 0/81720 RX: 0bps/0bps, dropped 0

Tested

Windows 11 (build 26200), MinGW GCC (WinLibs 15.2) Release build with BUILD_TESTING=ON, each test run three times (ctest --repeat until-fail:3).

  • guest_sce_net captures both outputs after sceNetInit. Ifconfig: the lo0 block byte for byte, the DNS section ending in ::, ::, and an eth0 block with the emulator's MAC when the host has an interface. Netstat: the header; a UDP socket with a 40-character name, unbound and blocking, as *....-., OPENED, *:* both ways and the name cut to 31; a non-blocking TCP socket listening on 127.0.0.1 as *....-*, LISTEN and its port; an epoll line with its name; the order UDP, TCP, epoll; and none of them once closed. The old check that both throw is gone.
  • The 41 ctest entries of every libSceNet and libSceNetCtl test executable (guest_sce_net, guest_net_ctl, net_epoll_lifetime, the datagram, dontwait, blocking-send, host-write, refused-connect and buffer-validation sets):
    • This PR (62a98cb02, d5649fc6a with main 97d33464c merged in): 41/41.
    • Control: main 97d33464c with only this PR's GuestSceNet.cpp: guest_sce_net stops on main's throw (what(): sceNetShowIfconfig); the other 40 pass.
    • main 97d33464c: 41/41.
  • Not run on Linux. tools/check_conventions.py --base origin/main passes.

Overlap

#8232 (sceNetShowNetstatEx) and #8225 (sceNetShowPolicy) have merged. With main merged in, CheckNetstat runs this PR's checks and then their two calls, and the debt file keeps their entries before and after this PR's. main's new argument check in sceNetEpollCreate (a null name or nonzero flags fail with EINVAL) is kept, so the epoll name this PR stores is never null. No open PR changes sceNetShowIfconfig or sceNetShowNetstat.

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
  • Fixes: none
  • Unblocks: none known on this machine; a title that logs these tables after sceNetInit stops on the throw today
  • GPUs tested: n/a (no GPU code)
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4992662954 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10502). Originally posted by [frankea](https://github.com/frankea) on 2026-10-24T05:04:02Z. --- ### What Since #9137 (04f2d9a60), `sceNetShowIfconfig` and `sceNetShowNetstat` throw once `sceNetInit` has run (`Initialized calls throw because native diagnostic collection and formatting are not implemented`), so a title that calls either for its log stops there. On a PS5 both return 0 and print plain-text tables to the caller's stdout. They now do the same, in the console's layout, with what the emulator knows. Before initialization both still return the not-initialized error. `sceNetShowIfconfig`: - An `eth0 (index=1)` block when `sceNetCtlGetInfo` has a host IPv4 interface to report, with the same values a title reads there: the MAC `02:50:53:35:00:01` (also `sceNetGetMacAddress`'s), the address, the netmask, the broadcast address derived from them and the MTU. The interface comes from a new `NetCtlHostIpv4Address_nid_no_patch`, next to the existing `NetCtlHostDnsServers_nid_no_patch`. - The console's `lo0 (index=2)` block as it printed it. - `dns addresses` with the two IPv4 servers `sceNetGetDnsInfo` returns, and `::, ::` for IPv6. `sceNetShowNetstat`: - The console's header, `--- ID, type, [self/R/S/RE/SE//NB], ... ---`, then one entry per socket (UDP, then TCP, then raw, as the console groups them, each by descending ID) and one line per epoll. - Each socket entry has the console's five lines: the ID, type, flags with self set and NB from `SO_NBIO`, the state (`OPENED` for UDP and raw; `LISTEN`, `ESTABLISHED` or `CLOSED` for TCP), the title's pid and the name; the local and remote address (`*` for the IPv4 wildcard and `[*]` for IPv6's, as the console writes them, `*` for port 0, and 28 trailing spaces, as the console pads them); and the send and receive buffer sizes `sceNetGetsockopt` reports. - The names given to `sceNetSocket` and `sceNetEpollCreate` were ignored. They are now kept, cut to 31 characters (the 32-byte name of `SceNetSockInfo`), for these lines. Left out, in the debt entry: ifconfig's IPv6 address, `UP6`, link status, traffic counters and times for `eth0`, the wireless interfaces, and the pool and statistics sections. Netstat lists only the title's own sockets and epolls, while the console lists every process's. The R, S, RE and SE flags, the field after the type, the queue lengths, rates and drop counts print as on an idle console socket, and the self flag on epoll lines is inferred from the socket lines. `sceNetShowNetstatWithMemory` keeps its existing output. Measurement: PS5 on firmware 13.40, 2026-10-19, from an elfldr payload process that called both after `sceNetInit`. Both returned 0. Ifconfig printed `eth0`, `lo0`, `wlan0` and `wlan1` blocks, then the DNS, pool and statistics sections. Netstat printed the header and an entry for every socket and epoll of every process, for example: ``` ID: 15 ( tcp, 0) ...*.-* ESTABLISHED pid=0x00000056 Local : 127.0.0.1:8084 Remote: 127.0.0.1:59637 Send-Q: 0/49032 TX: 0bps/0bps, dropped 0 (0) Recv-Q: 0/81720 RX: 0bps/0bps, dropped 0 ``` ### Tested Windows 11 (build 26200), MinGW GCC (WinLibs 15.2) Release build with `BUILD_TESTING=ON`, each test run three times (`ctest --repeat until-fail:3`). - `guest_sce_net` captures both outputs after `sceNetInit`. Ifconfig: the `lo0` block byte for byte, the DNS section ending in `::, ::`, and an `eth0` block with the emulator's MAC when the host has an interface. Netstat: the header; a UDP socket with a 40-character name, unbound and blocking, as `*....-.`, `OPENED`, `*:*` both ways and the name cut to 31; a non-blocking TCP socket listening on 127.0.0.1 as `*....-*`, `LISTEN` and its port; an epoll line with its name; the order UDP, TCP, epoll; and none of them once closed. The old check that both throw is gone. - The 41 ctest entries of every libSceNet and libSceNetCtl test executable (`guest_sce_net`, `guest_net_ctl`, `net_epoll_lifetime`, the datagram, dontwait, blocking-send, host-write, refused-connect and buffer-validation sets): - This PR (62a98cb02, d5649fc6a with `main` 97d33464c merged in): 41/41. - Control: `main` 97d33464c with only this PR's `GuestSceNet.cpp`: `guest_sce_net` stops on `main`'s throw (`what(): sceNetShowIfconfig`); the other 40 pass. - `main` 97d33464c: 41/41. - Not run on Linux. `tools/check_conventions.py --base origin/main` passes. ### Overlap #8232 (`sceNetShowNetstatEx`) and #8225 (`sceNetShowPolicy`) have merged. With `main` merged in, `CheckNetstat` runs this PR's checks and then their two calls, and the debt file keeps their entries before and after this PR's. `main`'s new argument check in `sceNetEpollCreate` (a null name or nonzero flags fail with `EINVAL`) is kept, so the epoll name this PR stores is never null. No open PR changes `sceNetShowIfconfig` or `sceNetShowNetstat`. ### 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] Fixes: none - [x] Unblocks: none known on this machine; a title that logs these tables after `sceNetInit` stops on the throw today - [x] GPUs tested: n/a (no GPU code) - [x] AI-assisted: yes (Claude Code)
harisibrar1 commented 2026-10-24 05:19:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T05:19:32Z.

Review: APPROVED


Checked against main 7966e590ef and shadPS4 net.cpp at 396c2a09a3 (both functions are logged stubs returning 0):

  • This merges cleanly into current main, and main still throws in both functions after init, so it isn't duplicated.
  • There's no process execution, and netstat lists only the emulator's own sockets and epolls (g_socks), never host-wide ones. The MAC is the fixed 02:50:53:35:00:01 from sceNetGetMacAddress, not the host adapter's.
  • Optional: the eth0 block and the DNS line put the host's real LAN address, netmask and DNS servers on stdout. Titles already get these from sceNetCtlGetInfo/sceNetGetDnsInfo, so this is only about them now landing in logs that users paste into issues. Not a blocker.
  • Looks good to me otherwise.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636984752 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10502#pullrequestreview-5636984752). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T05:19:32Z. **Review:** APPROVED --- Checked against main 7966e590ef and shadPS4 net.cpp at 396c2a09a3 (both functions are logged stubs returning 0): - This merges cleanly into current main, and main still throws in both functions after init, so it isn't duplicated. - There's no process execution, and netstat lists only the emulator's own sockets and epolls (`g_socks`), never host-wide ones. The MAC is the fixed `02:50:53:35:00:01` from `sceNetGetMacAddress`, not the host adapter's. - Optional: the `eth0` block and the DNS line put the host's real LAN address, netmask and DNS servers on stdout. Titles already get these from `sceNetCtlGetInfo`/`sceNetGetDnsInfo`, so this is only about them now landing in logs that users paste into issues. Not a blocker. - Looks good to me otherwise. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
MarcZX10 commented 2026-10-24 11:20:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T11:20:08Z.

Review: DISMISSED


The implementation is carefully scoped to the state the emulator actually knows, and the reported Windows test matrix is strong. I found two merge blockers:

  1. This PR is currently CONFLICTING with main (mergeStateStatus: DIRTY). Please rebase on current main and resolve the conflict, especially around CheckNetstat and the debt entry. #8225 merged on 2026-10-24, after this head was created.
  2. #8232 is still open and the PR description says it adds a line at the same CheckNetstat loop and debt entry, so whichever merges second has a conflict. The checklist currently says Depends on: none. Please coordinate the order with #8232's author and declare it in the checklist, as CONTRIBUTING requires for overlaps.

I found no separate runtime defect in the output formatting/state paths I inspected. The author reports all 41 focused Windows tests passing three times and the control on main behaving as described. Linux and the hosted full build were not run; this review did not rerun the Windows test suite locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638058973 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10502#pullrequestreview-5638058973). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T11:20:08Z. **Review:** DISMISSED --- The implementation is carefully scoped to the state the emulator actually knows, and the reported Windows test matrix is strong. I found two merge blockers: 1. This PR is currently `CONFLICTING` with main (`mergeStateStatus: DIRTY`). Please rebase on current main and resolve the conflict, especially around `CheckNetstat` and the debt entry. #8225 merged on 2026-10-24, after this head was created. 2. #8232 is still open and the PR description says it adds a line at the same `CheckNetstat` loop and debt entry, so whichever merges second has a conflict. The checklist currently says `Depends on: none`. Please coordinate the order with #8232's author and declare it in the checklist, as CONTRIBUTING requires for overlaps. I found no separate runtime defect in the output formatting/state paths I inspected. The author reports all 41 focused Windows tests passing three times and the control on main behaving as described. Linux and the hosted full build were not run; this review did not rerun the Windows test suite locally.
jotitadev commented 2026-10-27 02:42:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T02:42:20Z.

Review: COMMENTED


First Linux run, since the description says it was not run on Linux.

Bare-metal Linux x86_64: i7-8700, Ubuntu 26.04, kernel 7.0, glibc 2.43, GCC 15.2, Release, BUILD_TESTING=ON, full build. Head 62a98cb02 merged --no-commit onto main abed03546 (clean).

  • guest_sce_net: passes 3 of 3.
  • All 36 tests whose name contains net (the libSceNet and libSceNetCtl sets, among others): 36 of 36 pass.
  • Control, libSceNet/Export.cpp and libSceNetCtl/Export.cpp from main with the new test kept (full rebuild): guest_sce_net aborts with what(): sceNetShowIfconfig, as on Windows.
  • On this host the eth0 branch is the one taken, not the lo0-only fallback. I dumped the captured output from a local copy of the test. The machine has a physical NIC plus two Docker bridges (docker0, br-*), and NetCtlHostIpv4Address picked the physical NIC: its address, /24 netmask and broadcast, MTU:1500(max:1500), with the 02:50:53:35:00:01 MAC. So the bridges did not get in the way.
  • One data point, not a defect in this PR: on a systemd-resolved host the first DNS line is 127.0.0.53, 0.0.0.0, because NetCtlHostDnsServers reads /etc/resolv.conf, which points at the local stub. That matches what sceNetGetDnsInfo already reports on main.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5661629922 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10502#pullrequestreview-5661629922). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-27T02:42:20Z. **Review:** COMMENTED --- First Linux run, since the description says it was not run on Linux. Bare-metal Linux x86_64: i7-8700, Ubuntu 26.04, kernel 7.0, glibc 2.43, GCC 15.2, Release, `BUILD_TESTING=ON`, full build. Head `62a98cb02` merged `--no-commit` onto `main` `abed03546` (clean). - `guest_sce_net`: passes 3 of 3. - All 36 tests whose name contains `net` (the libSceNet and libSceNetCtl sets, among others): 36 of 36 pass. - Control, `libSceNet/Export.cpp` and `libSceNetCtl/Export.cpp` from `main` with the new test kept (full rebuild): `guest_sce_net` aborts with `what(): sceNetShowIfconfig`, as on Windows. - On this host the `eth0` branch is the one taken, not the `lo0`-only fallback. I dumped the captured output from a local copy of the test. The machine has a physical NIC plus two Docker bridges (`docker0`, `br-*`), and `NetCtlHostIpv4Address` picked the physical NIC: its address, `/24` netmask and broadcast, `MTU:1500(max:1500)`, with the `02:50:53:35:00:01` MAC. So the bridges did not get in the way. - One data point, not a defect in this PR: on a systemd-resolved host the first DNS line is `127.0.0.53, 0.0.0.0`, because `NetCtlHostDnsServers` reads `/etc/resolv.conf`, which points at the local stub. That matches what `sceNetGetDnsInfo` already reports on `main`. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
jotitadev commented 2026-10-27 06:33:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T06:33:56Z.

Review: COMMENTED


public_headers fails on this head, both on its own and merged onto current main (b7105f728):

getpid_nid_postfix: expected exactly one header declaration; found 2:
  core/libs/prx/libSceNet/Export.cpp:379, core/libs/prx/libkernel/include/Api.hpp:665

#10706 (merged 2026-10-24) added this audit: every export must be declared exactly once, in its library's public header. The new extern "C" int APS5_VABI getpid_nid_postfix(void); in libSceNet/Export.cpp duplicates the libkernel declaration. CI did not catch it because the linux/windows jobs were skipped on this head.

Fix: delete that line. Export.cpp already includes prx/libkernel/include/Api.hpp, which declares getpid_nid_postfix with the same signature.

 extern "C" bool NetCtlHostIpv4Address_nid_no_patch(std::uint32_t* address, std::uint32_t* netmask, std::uint32_t* mtu);
-extern "C" int APS5_VABI getpid_nid_postfix(void);

With that change the audit passes for this PR. The only remaining error is the sceKernelGetModuleInfoForUnwind one that is already on main from #9263 (#11718 fixes it). Export.cpp also passes a GCC 15.2 -fsyntax-only check with the build flags.

Checked on Linux (i7-8700, Ubuntu 26.04, GCC 15.2): core/libs/tests/test_public_headers.py --audit-only on head 62a98cb02 merged onto main b7105f728.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5663115592 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10502#pullrequestreview-5663115592). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-27T06:33:56Z. **Review:** COMMENTED --- `public_headers` fails on this head, both on its own and merged onto current `main` (`b7105f728`): ``` getpid_nid_postfix: expected exactly one header declaration; found 2: core/libs/prx/libSceNet/Export.cpp:379, core/libs/prx/libkernel/include/Api.hpp:665 ``` #10706 (merged 2026-10-24) added this audit: every export must be declared exactly once, in its library's public header. The new `extern "C" int APS5_VABI getpid_nid_postfix(void);` in `libSceNet/Export.cpp` duplicates the libkernel declaration. CI did not catch it because the `linux`/`windows` jobs were skipped on this head. Fix: delete that line. `Export.cpp` already includes `prx/libkernel/include/Api.hpp`, which declares `getpid_nid_postfix` with the same signature. ```diff extern "C" bool NetCtlHostIpv4Address_nid_no_patch(std::uint32_t* address, std::uint32_t* netmask, std::uint32_t* mtu); -extern "C" int APS5_VABI getpid_nid_postfix(void); ``` With that change the audit passes for this PR. The only remaining error is the `sceKernelGetModuleInfoForUnwind` one that is already on `main` from #9263 (#11718 fixes it). `Export.cpp` also passes a GCC 15.2 `-fsyntax-only` check with the build flags. Checked on Linux (i7-8700, Ubuntu 26.04, GCC 15.2): `core/libs/tests/test_public_headers.py --audit-only` on head `62a98cb02` merged onto `main` `b7105f728`. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
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!10502
No description provided.