net: implement getpeername and sceNetGetpeername (007 First Light) #2129
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2129
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2129"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@NevesHenry on GitHub · 2026-11-05 18:10 UTC · original
NevesHenry:kernel-getpeername→main· +129 −0 · 5 files · 4 commits · openGame: 007 First Light (PPSA11386), #1989
Problem
Neither the POSIX
getpeername(TXFFFiNldU8) norsceNetGetpeername(TCkRD0DWNLg) is exported, whilegetsocknameandsceNetGetsocknameare. Calls go to the unresolved import stub, which returns 0 without writing the address, so the caller reads whatever was already in its buffer as the peer address.Evidence (
_kyty.txtattached to #1989)Equeue create: ZHttpManagerOrbisCurl(line 26607), the game builds a loopback socket pair: socket 128 binds and listens with backlog 1, socket 129 connects,selectwaits, andaccept(128)returns 130.getsockname(129), thengetpeername(130), which hits the stub (line 26651:Unresolved import stub called [2] ... TXFFFiNldU8).ZRuntimeOnlineModule::HttpThreadwithout that pair. It looks like the usual check that the accepted end is the socket it connected, which can't pass on an unwritten address.TXFFFiNldU8too, and Gran Turismo 7 and Star Wars Jedi Survivor importTCkRD0DWNLg.Change
Net::GetpeernamefollowsNet::Getsockname: the host socket's peer address is converted to the guest sockaddr, and errors (ENOTCONN, EBADF, EFAULT) go through the same paths. It is registered as POSIXgetpeernamenext togetsockname, and assceNetGetpeernamenext tosceNetGetsockname. When the caller's buffer is shorter than the 16-byte address, it copies only that many bytes and writes back the truncated length, as FreeBSD'skern_getpeernamedoes.Testing
kernel_file_system_tests --network-only: a new check builds a loopback TCP pair and expects POSIXgetpeername(accepted)to equalgetsockname(connector)(what 007 does), Netgetpeername(connector)to equalgetsockname(accepted), and ENOTCONN on a socket without a peer. It also checks buffers of 8 and 0 bytes on both exports (truncated copy, the rest of the buffer untouched). It passes with the change. With main'ssrcfiles and the new test, it fails at "POSIX and Net getpeername exports resolve".git-clang-format(22.1.3) leaves thesrcchanges as they are.AI use: written with Claude Code (it scanned the issue logs, found the missing exports and drafted the change and test). I reviewed the code and checked the NIDs and the before/after test.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-11-05 18:16 UTC · original · edited 2026-11-22 23:48 UTC
No actionable comments were generated in the recent review.
Walkthrough
Adds
Getpeernameto the network layer and exposes it through the POSIX and Net library exports. The implementation retrieves and converts the host peer address, copies data up to the supplied capacity, and returns errors for invalid pointers or lookup failures. Tests check both exports with a connected TCP pair and verifyENOTCONNfor an unconnected socket.Suggested reviewers:
nmzikChange: Bug fix
Merge Risk:
Minimal · up to
e9630This adds getpeername and sceNetGetpeername, mirroring the existing getsockname behavior and replacing an unresolved import stub. Tests cover loopback peer addresses, ENOTCONN, and truncated buffers. No actionable merge-blocking risk remains.
Pre-merge checks:
4
Full details: Title check
Explanation
The title names the main change: implementing POSIX getpeername and sceNetGetpeername. The changeset adds Net::Getpeername, its NetGetpeername wrapper, the POSIX export, and a test for both exports, so the title matches the primary change. It is specific and concise, and it mentions the game context in parentheses.
Full details: Description check
Explanation
The description is directly related to the changeset. It explains the problem (unexported getpeername and sceNetGetpeername stubs), lists the implementation that mirrors Net::Getsockname with truncation behavior, and describes the new kernel_file_system_tests check. It is detailed and on-topic.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
9062a50f-8c86-44af-a426-2ac8fcc5e4c4Reviewing files that changed from the base of the PR and between
f3f43ea7f5ande9630f0635.src/libs/libKernel.cppsrc/libs/libNet.cppsrc/libs/network.cpptests/KernelFileSystemTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@coderabbitai[bot] on GitHub · 2026-11-05 18:16 UTC · original · edited 2026-11-06 13:24 UTC
On
src/libs/network.cppline 2215 (outdated):Return a truncated peer address for a short buffer.
If a connected socket supplies an address length below 16,
ConvertHostSockaddrreturnsEINVALwithout writing the address. FreeBSDgetpeernameinstead succeeds, truncates the address to the supplied capacity, and reports the full address length. Convert into a temporary 16-byte guest address, then copy only the caller's capacity and set*addrlento 16. (man.freebsd.org)✅ Addressed in commit
ce9981b@coderabbitai[bot] on GitHub · 2026-11-05 18:17 UTC · original · reviewed
Actionable comments posted: 1
429a3ddf-a6ea-4fbf-bfc2-ea2b43b4fa6cReviewing files that changed from the base of the PR and between
a0268f1de4and5676638d1b.src/libs/libKernel.cppsrc/libs/libNet.cppsrc/libs/network.cppsrc/libs/network.htests/KernelFileSystemTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@NevesHenry on GitHub · 2026-11-06 13:20 UTC · original
On
src/libs/network.cppline 2215 (outdated):Thanks, changed in
ce9981bf. One difference from the suggestion: FreeBSD 9'skern_getpeernamewrites back the truncated length (len = MIN(*alen, sa->sa_len); *alen = len;), not the full 16 bytes, so this copiesmin(*addrlen, 16)bytes and stores that length. A nulladdris EFAULT only when bytes have to be copied.CheckSocketPeerNamenow covers 8- and 0-byte buffers on both exports; with the previousnetwork.cppit fails at "POSIX getpeername truncates to a smaller buffer".(Written with Claude Code.)
@coderabbitai[bot] on GitHub · 2026-11-06 13:23 UTC · original · reviewed
955f2459-bcca-4a5c-89a6-60ceb53b9092Reviewing files that changed from the base of the PR and between
5676638d1bandce9981bf2c.src/libs/network.cpptests/KernelFileSystemTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@coderabbitai[bot] on GitHub · 2026-11-06 13:25 UTC · original
On
src/libs/network.cppline 2215 (outdated):Analysis chain
Script executed:
Length of output: 1982
@NevesHenryThanks for the fix and the correction. I checked FreeBSD 9.3’skern_getpeername: it writes back the truncated length. My suggestion to return 16 was wrong.The updated implementation copies and reports the truncated length. Thanks for adding the short-buffer tests.
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
Review thread resolved.
You are interacting with an AI system.
@coderabbitai[bot] on GitHub · 2026-11-10 01:10 UTC · original · reviewed
1331c96a-deaf-408e-8c6f-acbbef3be937Reviewing files that changed from the base of the PR and between
ce9981bf2candf3f43ea7f5.src/libs/libKernel.cppsrc/libs/network.cpptests/KernelFileSystemTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.