feat(libSceNetCtl): add sceNetCtlGetIfStat #4682

Merged
bubblegg merged 4 commits from upstream-pr/4682 into main 2026-10-13 07:26:48 +00:00
bubblegg commented 2026-10-12 18:57:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by bubblegg on 2026-10-12T18:57:41Z.


What

Adds sceNetCtlGetIfStat. PPSA09030 stops at load on main:

FAIL: unresolved ELF import teuK4QnJTGg from libSceNetCtl.prx

The title's VivoxNative.prx calls it with one pointer to a 56-byte structure
and reads 64-bit values at offsets 8 and 16 after a non-negative result, then
calls sceNetCtlGetState. The structure is laid out as device (u32), sent bytes
(u64), received bytes (u64), 8 reserved u32. The function fills the byte
counters from the host's hardware interfaces that are up, and returns
SCE_NET_CTL_ERROR_NOT_CONNECTED when the host has no address, as
sceNetCtlGetState reports it. The signature comes from that call site; I found
no public header that declares it.

Tested

Windows 11, WinLibs GCC 16.1.0. guest_sce_net passes and covers the new
function (null pointer, result against sceNetCtlGetState, counters not
decreasing). PPSA09030 gets past this import and stops at the next one
(QWSxBzf6lAg, libSceSsl), which is a separate change. The Linux path is not
built or run by me.

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; silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA09030 #4680
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4833743256 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4682). Originally posted by [bubblegg](https://github.com/bubblegg) on 2026-10-12T18:57:41Z. --- ### What Adds sceNetCtlGetIfStat. PPSA09030 stops at load on main: FAIL: unresolved ELF import teuK4QnJTGg from libSceNetCtl.prx The title's VivoxNative.prx calls it with one pointer to a 56-byte structure and reads 64-bit values at offsets 8 and 16 after a non-negative result, then calls sceNetCtlGetState. The structure is laid out as device (u32), sent bytes (u64), received bytes (u64), 8 reserved u32. The function fills the byte counters from the host's hardware interfaces that are up, and returns SCE_NET_CTL_ERROR_NOT_CONNECTED when the host has no address, as sceNetCtlGetState reports it. The signature comes from that call site; I found no public header that declares it. ### Tested Windows 11, WinLibs GCC 16.1.0. guest_sce_net passes and covers the new function (null pointer, result against sceNetCtlGetState, counters not decreasing). PPSA09030 gets past this import and stops at the next one (QWSxBzf6lAg, libSceSsl), which is a separate change. The Linux path is not built or run by me. ### 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 - [x] Unimplemented paths throw; silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [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: PPSA09030 #4680 - [x] AI-assisted: yes
MarcZX10 commented 2026-10-12 19:11:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T19:11:20Z.

Code review location: core/libs/prx/libSceNetCtl/Export.cpp; line 10

@@ -5,14 +5,17 @@
 #include <iphlpapi.h>
 #else
 #include <ifaddrs.h>
+#include <linux/if_link.h>
 #include <net/if.h>
 #include <netinet/in.h>

This #else branch also compiles on macOS, but <linux/if_link.h> and <netpacket/packet.h> are Linux-only headers. Since AnyPS5 supports macOS builds, this include will fail there before the new function can compile. Could the Linux-specific traffic-stat implementation be guarded with __linux__ and use a macOS-compatible path (or an explicit unsupported fallback) for other non-Windows platforms?

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4251490182 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4682#discussion_r4251490182). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T19:11:20Z. **Code review location:** `core/libs/prx/libSceNetCtl/Export.cpp`; line 10 ~~~~diff @@ -5,14 +5,17 @@ #include <iphlpapi.h> #else #include <ifaddrs.h> +#include <linux/if_link.h> #include <net/if.h> #include <netinet/in.h> ~~~~ --- This `#else` branch also compiles on macOS, but `<linux/if_link.h>` and `<netpacket/packet.h>` are Linux-only headers. Since AnyPS5 supports macOS builds, this include will fail there before the new function can compile. Could the Linux-specific traffic-stat implementation be guarded with `__linux__` and use a macOS-compatible path (or an explicit unsupported fallback) for other non-Windows platforms?
MarcZX10 commented 2026-10-12 19:23:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T19:23:26Z.

Code review location: core/libs/prx/libSceNetCtl/Export.cpp; line 105

@@ -78,12 +83,49 @@ static bool HostHasAddress(int family) {
 #endif
 }
 
+static void HostTraffic(std::uint64_t& sent, std::uint64_t& received) {
+    sent = 0;
+    received = 0;
+#ifdef _WIN32
+    MIB_IF_TABLE2* table = nullptr;
+    if (GetIfTable2(&table) != NO_ERROR) throw std::runtime_error("sceNetCtlGetIfStat: the host interface table is unavailable");
+    for (ULONG index = 0; index < table->NumEntries; ++index) {
+        const auto& row = table->Table[index];
+        if (row.OperStatus != IfOperStatusUp || row.Type == IF_TYPE_SOFTWARE_LOOPBACK || !row.InterfaceAndOperStatusFlags.HardwareInterface) continue;
+        sent += row.OutOctets;
+        received += row.InOctets;
+    }
+    FreeMibTable(table);
+#elif defined(__linux__)
+    ifaddrs* interfaces = nullptr;
+    if (getifaddrs(&interfaces) != 0) throw std::runtime_error("sceNetCtlGetIfStat: the host interface list is unavailable");
+    for (auto* item = interfaces; item; item = item->ifa_next) {
+        if (!item->ifa_addr || item->ifa_addr->sa_family != AF_PACKET || !item->ifa_data) continue;
+        if (!(item->ifa_flags & IFF_UP) || (item->ifa_flags & IFF_LOOPBACK)) continue;
+        const auto* stats = static_cast<const rtnl_link_stats*>(item->ifa_data);

rtnl_link_stats::tx_bytes and rx_bytes are 32-bit counters (if_link.h), while NetCtlIfStat exposes 64-bit totals. Widening here happens only after the 32-bit host counters have wrapped, so this reports incorrect totals after 4 GiB per interface. Could this read Linux rtnl_link_stats64 counters (or another 64-bit interface-counter API) instead? A test with a counter value above UINT32_MAX would cover the regression.

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4251584960 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4682#discussion_r4251584960). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T19:23:26Z. **Code review location:** `core/libs/prx/libSceNetCtl/Export.cpp`; line 105 ~~~~diff @@ -78,12 +83,49 @@ static bool HostHasAddress(int family) { #endif } +static void HostTraffic(std::uint64_t& sent, std::uint64_t& received) { + sent = 0; + received = 0; +#ifdef _WIN32 + MIB_IF_TABLE2* table = nullptr; + if (GetIfTable2(&table) != NO_ERROR) throw std::runtime_error("sceNetCtlGetIfStat: the host interface table is unavailable"); + for (ULONG index = 0; index < table->NumEntries; ++index) { + const auto& row = table->Table[index]; + if (row.OperStatus != IfOperStatusUp || row.Type == IF_TYPE_SOFTWARE_LOOPBACK || !row.InterfaceAndOperStatusFlags.HardwareInterface) continue; + sent += row.OutOctets; + received += row.InOctets; + } + FreeMibTable(table); +#elif defined(__linux__) + ifaddrs* interfaces = nullptr; + if (getifaddrs(&interfaces) != 0) throw std::runtime_error("sceNetCtlGetIfStat: the host interface list is unavailable"); + for (auto* item = interfaces; item; item = item->ifa_next) { + if (!item->ifa_addr || item->ifa_addr->sa_family != AF_PACKET || !item->ifa_data) continue; + if (!(item->ifa_flags & IFF_UP) || (item->ifa_flags & IFF_LOOPBACK)) continue; + const auto* stats = static_cast<const rtnl_link_stats*>(item->ifa_data); ~~~~ --- `rtnl_link_stats::tx_bytes` and `rx_bytes` are 32-bit counters (`if_link.h`), while `NetCtlIfStat` exposes 64-bit totals. Widening here happens only after the 32-bit host counters have wrapped, so this reports incorrect totals after 4 GiB per interface. Could this read Linux `rtnl_link_stats64` counters (or another 64-bit interface-counter API) instead? A test with a counter value above `UINT32_MAX` would cover the regression.
bubblegg commented 2026-10-12 19:30:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by bubblegg on 2026-10-12T19:30:59Z.

Code review location: core/libs/prx/libSceNetCtl/Export.cpp; line 10

@@ -5,14 +5,17 @@
 #include <iphlpapi.h>
 #else
 #include <ifaddrs.h>
+#include <linux/if_link.h>
 #include <net/if.h>
 #include <netinet/in.h>

fixed in 071f76d, thanks

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4251639375 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4682#discussion_r4251639375). Originally posted by [bubblegg](https://github.com/bubblegg) on 2026-10-12T19:30:59Z. **Code review location:** `core/libs/prx/libSceNetCtl/Export.cpp`; line 10 ~~~~diff @@ -5,14 +5,17 @@ #include <iphlpapi.h> #else #include <ifaddrs.h> +#include <linux/if_link.h> #include <net/if.h> #include <netinet/in.h> ~~~~ --- fixed in 071f76d, thanks
bubblegg commented 2026-10-12 19:31:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by bubblegg on 2026-10-12T19:31:03Z.

Code review location: core/libs/prx/libSceNetCtl/Export.cpp; line 105

@@ -78,12 +83,49 @@ static bool HostHasAddress(int family) {
 #endif
 }
 
+static void HostTraffic(std::uint64_t& sent, std::uint64_t& received) {
+    sent = 0;
+    received = 0;
+#ifdef _WIN32
+    MIB_IF_TABLE2* table = nullptr;
+    if (GetIfTable2(&table) != NO_ERROR) throw std::runtime_error("sceNetCtlGetIfStat: the host interface table is unavailable");
+    for (ULONG index = 0; index < table->NumEntries; ++index) {
+        const auto& row = table->Table[index];
+        if (row.OperStatus != IfOperStatusUp || row.Type == IF_TYPE_SOFTWARE_LOOPBACK || !row.InterfaceAndOperStatusFlags.HardwareInterface) continue;
+        sent += row.OutOctets;
+        received += row.InOctets;
+    }
+    FreeMibTable(table);
+#elif defined(__linux__)
+    ifaddrs* interfaces = nullptr;
+    if (getifaddrs(&interfaces) != 0) throw std::runtime_error("sceNetCtlGetIfStat: the host interface list is unavailable");
+    for (auto* item = interfaces; item; item = item->ifa_next) {
+        if (!item->ifa_addr || item->ifa_addr->sa_family != AF_PACKET || !item->ifa_data) continue;
+        if (!(item->ifa_flags & IFF_UP) || (item->ifa_flags & IFF_LOOPBACK)) continue;
+        const auto* stats = static_cast<const rtnl_link_stats*>(item->ifa_data);

guarded with linux in dedbe7e, other platforms throw

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4251639943 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4682#discussion_r4251639943). Originally posted by [bubblegg](https://github.com/bubblegg) on 2026-10-12T19:31:03Z. **Code review location:** `core/libs/prx/libSceNetCtl/Export.cpp`; line 105 ~~~~diff @@ -78,12 +83,49 @@ static bool HostHasAddress(int family) { #endif } +static void HostTraffic(std::uint64_t& sent, std::uint64_t& received) { + sent = 0; + received = 0; +#ifdef _WIN32 + MIB_IF_TABLE2* table = nullptr; + if (GetIfTable2(&table) != NO_ERROR) throw std::runtime_error("sceNetCtlGetIfStat: the host interface table is unavailable"); + for (ULONG index = 0; index < table->NumEntries; ++index) { + const auto& row = table->Table[index]; + if (row.OperStatus != IfOperStatusUp || row.Type == IF_TYPE_SOFTWARE_LOOPBACK || !row.InterfaceAndOperStatusFlags.HardwareInterface) continue; + sent += row.OutOctets; + received += row.InOctets; + } + FreeMibTable(table); +#elif defined(__linux__) + ifaddrs* interfaces = nullptr; + if (getifaddrs(&interfaces) != 0) throw std::runtime_error("sceNetCtlGetIfStat: the host interface list is unavailable"); + for (auto* item = interfaces; item; item = item->ifa_next) { + if (!item->ifa_addr || item->ifa_addr->sa_family != AF_PACKET || !item->ifa_data) continue; + if (!(item->ifa_flags & IFF_UP) || (item->ifa_flags & IFF_LOOPBACK)) continue; + const auto* stats = static_cast<const rtnl_link_stats*>(item->ifa_data); ~~~~ --- guarded with __linux__ in dedbe7e, other platforms throw
MarcZX10 commented 2026-10-12 19:32:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T19:32:18Z.

Code review location: core/libs/prx/libSceNetCtl/Export.cpp; line 105

@@ -78,12 +83,49 @@ static bool HostHasAddress(int family) {
 #endif
 }
 
+static void HostTraffic(std::uint64_t& sent, std::uint64_t& received) {
+    sent = 0;
+    received = 0;
+#ifdef _WIN32
+    MIB_IF_TABLE2* table = nullptr;
+    if (GetIfTable2(&table) != NO_ERROR) throw std::runtime_error("sceNetCtlGetIfStat: the host interface table is unavailable");
+    for (ULONG index = 0; index < table->NumEntries; ++index) {
+        const auto& row = table->Table[index];
+        if (row.OperStatus != IfOperStatusUp || row.Type == IF_TYPE_SOFTWARE_LOOPBACK || !row.InterfaceAndOperStatusFlags.HardwareInterface) continue;
+        sent += row.OutOctets;
+        received += row.InOctets;
+    }
+    FreeMibTable(table);
+#elif defined(__linux__)
+    ifaddrs* interfaces = nullptr;
+    if (getifaddrs(&interfaces) != 0) throw std::runtime_error("sceNetCtlGetIfStat: the host interface list is unavailable");
+    for (auto* item = interfaces; item; item = item->ifa_next) {
+        if (!item->ifa_addr || item->ifa_addr->sa_family != AF_PACKET || !item->ifa_data) continue;
+        if (!(item->ifa_flags & IFF_UP) || (item->ifa_flags & IFF_LOOPBACK)) continue;
+        const auto* stats = static_cast<const rtnl_link_stats*>(item->ifa_data);

Thanks—the current head reads Linux sysfs byte counters directly into uint64_t, and the added helper regression uses a value above UINT32_MAX. That resolves my counter-width concern as well; I had initially reviewed the earlier rtnl_link_stats version. The __linux__ guard also resolves the macOS-header issue.

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4251649013 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4682#discussion_r4251649013). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T19:32:18Z. **Code review location:** `core/libs/prx/libSceNetCtl/Export.cpp`; line 105 ~~~~diff @@ -78,12 +83,49 @@ static bool HostHasAddress(int family) { #endif } +static void HostTraffic(std::uint64_t& sent, std::uint64_t& received) { + sent = 0; + received = 0; +#ifdef _WIN32 + MIB_IF_TABLE2* table = nullptr; + if (GetIfTable2(&table) != NO_ERROR) throw std::runtime_error("sceNetCtlGetIfStat: the host interface table is unavailable"); + for (ULONG index = 0; index < table->NumEntries; ++index) { + const auto& row = table->Table[index]; + if (row.OperStatus != IfOperStatusUp || row.Type == IF_TYPE_SOFTWARE_LOOPBACK || !row.InterfaceAndOperStatusFlags.HardwareInterface) continue; + sent += row.OutOctets; + received += row.InOctets; + } + FreeMibTable(table); +#elif defined(__linux__) + ifaddrs* interfaces = nullptr; + if (getifaddrs(&interfaces) != 0) throw std::runtime_error("sceNetCtlGetIfStat: the host interface list is unavailable"); + for (auto* item = interfaces; item; item = item->ifa_next) { + if (!item->ifa_addr || item->ifa_addr->sa_family != AF_PACKET || !item->ifa_data) continue; + if (!(item->ifa_flags & IFF_UP) || (item->ifa_flags & IFF_LOOPBACK)) continue; + const auto* stats = static_cast<const rtnl_link_stats*>(item->ifa_data); ~~~~ --- Thanks—the current head reads Linux sysfs byte counters directly into `uint64_t`, and the added helper regression uses a value above `UINT32_MAX`. That resolves my counter-width concern as well; I had initially reviewed the earlier `rtnl_link_stats` version. The `__linux__` guard also resolves the macOS-header issue.
github-actions[bot] commented 2026-10-12 21:11:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T21:11:04Z.


Progress report (682ef0c → 071f76d)

📈 System libraries: 86.37% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libSceNetCtl sceNetCtlGetIfStat
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132674336 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4682#issuecomment-6132674336). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T21:11:04Z. --- <!-- progress-report --> ### Progress report (682ef0c → 071f76d) 📈 **System libraries**: 86.37% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libSceNetCtl | `sceNetCtlGetIfStat` | </details>
adriadam10 commented 2026-10-12 21:17:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T21:17:28Z.


Checked the layout against SharpProspero's SceNetCtlIfStat and the error values against KytyPS5; core/libs builds and its 24 tests pass on main + this PR, and guest_sce_net no longer compiles without the change.

Added one commit on top: a TechnicalDebt line under "Unknown function info" for the signature inferred from the call site, the device kind fixed at 0, and the counters being host totals rather than "since cleared". Rebased onto current main.

The Windows path (GetIfTable2) was not run here. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132766978 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4682#issuecomment-6132766978). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-12T21:17:28Z. --- Checked the layout against SharpProspero's `SceNetCtlIfStat` and the error values against KytyPS5; `core/libs` builds and its 24 tests pass on main + this PR, and `guest_sce_net` no longer compiles without the change. Added one commit on top: a TechnicalDebt line under "Unknown function info" for the signature inferred from the call site, the device kind fixed at 0, and the counters being host totals rather than "since cleared". Rebased onto current main. The Windows path (`GetIfTable2`) was not run here. Merging once CI is green.
adriadam10 commented 2026-10-13 07:26:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T07:26:44Z.


The red eligibility check was a GitHub API rate limit on the runner (API rate limit exceeded for installation), not this diff; re-ran it. Nothing else changed since the earlier review: merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140540206 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4682#issuecomment-6140540206). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T07:26:44Z. --- The red `eligibility` check was a GitHub API rate limit on the runner (`API rate limit exceeded for installation`), not this diff; re-ran it. Nothing else changed since the earlier review: merging once CI 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!4682
No description provided.