feat(libSceNet): return SO_PROTOCOL for raw sockets with an explicit protocol #14902

Merged
edubox merged 2 commits from upstream-pr/14902 into main 2026-11-06 22:29:53 +00:00
edubox commented 2026-11-01 23:55:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-11-01T23:55:55Z.


What

sceNetGetsockopt threw for SO_PROTOCOL (0x1016) on every raw socket. It now returns the protocol of the entry FreeBSD's pffindproto selects: the requested number for the exact raw entries in in_proto.c and in6_proto.c, or the wildcard entry's pr_protocol 0 for any other nonzero protocol, which sogetopt returns. The host mirrors the IPv4 and IPv6 tables.

A raw socket created with protocol 0 still throws because its selection is not mapped. FreeBSD's socreate calls pffindtype for zero rather than pffindproto, and rip_attach does not reject it, so this is an unsupported path here and not a console rejection. The debt entry now says exactly that.

The truncated integer output (up to *optlen, minimum of 4) and the existing null-pointer EINVAL checks are unchanged.

Tested

  • Linux, GCC 16.2.1, Release, BUILD_TESTING=ON: built guest_net_protocol_tests and the new guest_net_raw_protocol_tests; both pass under unshare -Urn after bringing lo up (which grants CAP_NET_RAW).
  • The new test checks a raw ICMP socket (an exact entry) over capacities 0, 1, 3, 4 and 8, a raw socket created with unlisted protocol 17 (the wildcard entry, expected to report 0), and the null-pointer errors. The protocol-0 throw pin is gone.
  • The raw IPv6 case is not tested: sceNetSocket currently sets IPV6_V6ONLY on raw IPv6 sockets and the host rejects it with EINVAL, which is unrelated to this change.
  • python3 tools/check_conventions.py --base origin/main: passed.

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
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5112842450 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14902). Originally posted by [edubox](https://github.com/edubox) on 2026-11-01T23:55:55Z. --- ### What `sceNetGetsockopt` threw for `SO_PROTOCOL` (0x1016) on every raw socket. It now returns the protocol of the entry FreeBSD's `pffindproto` selects: the requested number for the exact raw entries in `in_proto.c` and `in6_proto.c`, or the wildcard entry's `pr_protocol` 0 for any other nonzero protocol, which `sogetopt` returns. The host mirrors the IPv4 and IPv6 tables. A raw socket created with protocol 0 still throws because its selection is not mapped. FreeBSD's `socreate` calls `pffindtype` for zero rather than `pffindproto`, and `rip_attach` does not reject it, so this is an unsupported path here and not a console rejection. The debt entry now says exactly that. The truncated integer output (up to `*optlen`, minimum of 4) and the existing null-pointer `EINVAL` checks are unchanged. ### Tested - Linux, GCC 16.2.1, Release, `BUILD_TESTING=ON`: built `guest_net_protocol_tests` and the new `guest_net_raw_protocol_tests`; both pass under `unshare -Urn` after bringing `lo` up (which grants `CAP_NET_RAW`). - The new test checks a raw ICMP socket (an exact entry) over capacities 0, 1, 3, 4 and 8, a raw socket created with unlisted protocol 17 (the wildcard entry, expected to report 0), and the null-pointer errors. The protocol-0 throw pin is gone. - The raw IPv6 case is not tested: `sceNetSocket` currently sets `IPV6_V6ONLY` on raw IPv6 sockets and the host rejects it with `EINVAL`, which is unrelated to this change. - `python3 tools/check_conventions.py --base origin/main`: passed. ### 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 - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!14902
No description provided.