fix(libSceNet): fill the address and port fields in sceNetGetSockInfo #7959
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7959"
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?
Imported from boykopovar/AnyPS5. Originally posted by Lindamea1 on 2026-10-19T16:06:23Z.
What
On
main,sceNetGetSockInfo(s, info, n, flags)returns 0 for any socket in the library's table and writes nothing toinfo; only an unknownsfails, with0x80410109(EBADF). It was not listed under Silent stubs either. A probe that fills the record with0xAAbefore the call prints, againstmain:and the same for a connected TCP client and the socket
sceNetAcceptreturned.Monster Hunter Wilds (PPSA24191, v01.041.040) reads these fields. In its relinked executable, the socket class calls
sceNetGetSockInfo(s, &info, 1, 0)on an uninitialised 0xA0-byte stack buffer at0xedd5f9b,0xedd6296and0xedd63e2, aftersceNetConnect(0xedd5f65),sceNetBind(0xedd6273) andsceNetAccept(0xedd63b7). It storesinfo+0x34andsceNetNtohs(info+0x3c)as the socket's local address and port, and after the accept alsoinfo+0x38andsceNetNtohs(info+0x3e)as the peer's. It checks only the sign of the result. This is from the disassembly (the PLT slots resolve to the NIDs ofsceNetGetSockInfo,sceNetNtohs,sceNetConnect,sceNetBindandsceNetAccept); I have not seen these calls in a run.SharpProspero and shadPS4 give the same 0xA0-byte layout:
sat 0x24,socket_typeat 0x28,local_adrandremote_adrat 0x34 and 0x38,local_portandremote_portat 0x3c and 0x3e,flagsat 0x48, andrecv_buffer_sizeandsend_buffer_sizeat 0x64 and 0x68. shadPS4 marks the ports as network byte order (net_types.h#L302), and the title passes them throughsceNetNtohs. Both give the status flagsSELFas 0x1 andNONBLOCKas 0x200000 (Socket.cs#L665-L687, net_types.h#L278-L288). SharpProspero documents the result as the number of records written (Socket.cs#L802-L808). shadPS4 fills one record from the host socket's name and peer,SELFplusNONBLOCKfor a non-blocking socket, and the buffer sizes set on the socket (net.cpp#L428-L492). ItssceNetGetSockInforeturns 1 for one socket,EINVALfor a nullinfo(the socket count whensis below 0) or annof 0 or less, and lists every socket for ansbelow 0. SharpProspero also names two request flags (Socket.cs#L701-L705):SockInfoTimeWait(0x40), "also list sockets in the TIME_WAIT state", and, forsceNetGetSockInfo6,SockInfo6Ipv46(0x1000), "report both IPv4 and IPv6 sockets".sceNetGetSockInfonow writes one record for an IPv4 socket and returns 1. The record holdss,socket_type, the local address and port from the host socket'sgetsocknameand the remote ones fromgetpeername(0 while it has no peer) in network byte order,flagswithSELFand, whenSO_NBIOis set,NONBLOCK, and the receive and send buffer sizessceNetGetsockoptreturns forSO_RCVBUFandSO_SNDBUF: the size set on the socket, else the host socket's. Every other field is 0. A nullinfoor annbelow 1 fails with0x80410116(EINVAL), and an unknown socket still fails withEBADF.An
sbelow 0 lists the library's sockets as shadPS4 does: with a nullinfothe call returns their number, otherwise it writes their records in socket-number order untilnare written and returns how many it wrote. A socket closed during the call is skipped. Two answers differ from shadPS4. An IPv6 socket fails with0x8041012f(EAFNOSUPPORT), since the record has room only for an IPv4 address, and is left out of the count and the list; shadPS4 lists it with the addresses and ports 0 and returns 1 for it alone.SockInfo6Ipv46suggests that IPv6 sockets are listed bysceNetGetSockInfo6. And aflagsbit other than 0x40 fails withEINVAL, where shadPS4 ignoresflags. 0x40 is accepted and lists the same sockets: a closed socket leaves the library's table at once, so none is kept in TIME_WAIT.The name, pid, policy, priority, queue lengths, virtual ports, state, bandwidth, and drop and wait counts are 0, and no status flag other than
SELFandNONBLOCKis set. shadPS4 also fills the name, policy, priority and state (and, on its currentmain, the receive queue length), and falls back to itsDefaultSendBufferandDefaultReceiveBufferwhere no size was set; here a socket without a set size reports the host's, assceNetGetsockoptalready does. The new entry indocs/dev/debt/libSceNet.mdlists these and the IPv6 andflagshandling. Not measured on a console.Tested
Gentoo Linux, kernel 7.2.8, GCC 16.2.1, glibc 2.43, Release,
BUILD_TESTING=ON, onmain1ed63f63c.guest_sce_netwith the newCheckSockInfo: for an unbound UDP socket, the same socket bound to 127.0.0.1:0 and later connected, a listening TCP socket, a connected TCP client and the accepted socket,sceNetGetSockInfo(s, buffer, 2, 0)returns 1 and leaves the second record as it was. The first 0xA0 bytes equal a record built fromsceNetGetsockname,sceNetGetpeernameandsceNetGetsockopt:sat 0x24, the type at 0x28, the addresses at 0x34 and 0x38, the ports at 0x3c and 0x3e,flags0x1 at 0x48, theSO_RCVBUFandSO_SNDBUFsizes (above 0) at 0x64 and 0x68, and every other byte 0. AfterSO_NBIO1,SO_RCVBUF65536 andSO_SNDBUF32768 on the UDP socket,flagsis 0x200001 and the sizes are 65536 and 32768. A nullinfoand annof 0 fail with errno 22, and so does annof 0 withs-1;flags1, 0x41 and 0x1000 fail with errno 22, for one socket and for the count; an IPv6 socket fails with errno 47 (where the host has no IPv6, creating the socket fails with 47 instead); none of these writes the buffer. Withflags0x40 the UDP socket's record is the same. A closed socket fails with errno 9.The new
RequireSockInfoListreads the count (s-1, nullinfo), lists one record more than that and checks that the call returns the count and leaves the extra record as it was, that the sockets come in increasing order, that each record equals the onesceNetGetSockInforeturns for that socket alone, and thatn1 writes only the first. With the four IPv4 sockets and the IPv6 one open, the list forflags0 and for 0x40 is the sockets open before the check plus the four IPv4 ones; after they are closed it is the sockets open before. The test passed 20 runs in a row, about 1.2 s each.With only
Export.cpptaken frommain, the test aborts inRequireSockInfoList(gdb backtrace): its first call expects the count wheremainfailss-1 withEBADF. WithExport.cppfrom this PR's previous revision, the first listing throwsruntime_error(listing all sockets (s < 0) is not supported) and the test terminates.The probe above against this branch prints
sceNetGetSockInfo(s=6, info, 1, 0)=1 info.s=0x6 local_adr=0100007f local_port=0x8eac remote_adr=00000000 remote_port=000000 (getsockname port 44174): 127.0.0.1 and port 44174, both in network byte order. For the TCP pair, the accepted socket's remote port is the client's local port and the other way round. A second probe printsflags=0x1 recv_buffer_size=212992 send_buffer_size=212992for a new UDP socket, the sizessceNetGetsockoptreturns for it, andflags=0x200001 recv_buffer_size=65536 send_buffer_size=32768afterSO_NBIO1,SO_RCVBUF65536 andSO_SNDBUF32768. Againstmainthe call returns 0 and these fields keep the0xAAfill.A third probe opens a UDP socket bound to 127.0.0.1 and made non-blocking (6), a listening TCP socket (8), a connected client (10), the accepted socket (12) and an IPv6 UDP socket (14). It prints the ports in host order:
The two-record list holds sockets 6 and 8, the 0x40 list the same four records as the first, and the last list sockets 6, 8 and 12.
Tests selected by
tools/select_tests.pyfor this diff (227 of 1672): 227 passed, 0 failed, 0 skipped.tools/check_compile.py: the 2 changed translation units compile.Windows:
Export.cppandGuestSceNet.cppcompile withx86_64-w64-mingw32-g++16.2.0 (-fsyntax-only -Wall -Wextra) without warnings, as onmain. This is a syntax check, not a Windows build or run.tools/check_conventions.pypasses againstmain.tools/pr_overlap.py --branchreports no overlapping lines. It could not compare #5836, #6044, #7201, #7332 and #8106, which conflict withmain; merged with this branch, each conflicts in the same files, with as many conflict hunks, as withmain.Not run on Windows, macOS or a console.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T16:25:57Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceNet/Export.cppcore/libs/tests/GuestSceNet.cppdocs/dev/debt/libSceNet.mdcore/libs/tests/GuestSceNet.cppcore/libs/prx/libSceNet/Export.cppcore/libs/prx/libSceNet/Export.cppcore/libs/tests/GuestSceNet.cppcore/libs/prx/libSceNet/Export.cppdocs/dev/debt/libSceNet.mdImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T04:11:42Z.
Thanks, the single-socket record looks right and matches shadPS4's layout and return value (one record, returns 1). One concern before merge: some calls that
mainanswers without stopping now throw.s < 0(all sockets) used to fail withEBADF; now it throws. shadPS4 implements it: withinfo == nullptrit returns the number of sockets, otherwise it fills up tonrecords for every open socket and returns how many it wrote. Could you implement that here (the table isg_socks), or at least keep returning an error instead of throwing?flags != 0and IPv6 sockets used to return 0 and now throw. If you know what the console does for nonzero flags, please note it; otherwise an error return would be safer than a throw for a call that previously succeeded.The debt-file conflict with
mainis only the neighbouringTCP_NODELAYentry.Imported from boykopovar/AnyPS5. Originally posted by Lindamea1 on 2026-10-20T06:27:49Z.
Thanks. Pushed
a05db60c8, rebased ontomain1ed63f63c(the debt conflict was theTCP_NODELAYentry next to this one):s < 0now lists the sockets as shadPS4 does: withinfo == nullptrit returns their number, otherwise it writes up tonrecords in socket order and returns how many it wrote, skipping a socket closed during the call.EAFNOSUPPORT, since the record has room only for an IPv4 address, and is left out of the count and the list. shadPS4 lists it with the addresses and ports 0 and returns 1 for it alone. SharpProspero'sSockInfo6Ipv46request flag (0x1000, "report both IPv4 and IPv6 sockets") suggestssceNetGetSockInfo6is where IPv6 sockets are listed. If you'd rather keep that call succeeding the way shadPS4 does, I can switch to that.flagsbit other than 0x40 fails withEINVAL, where shadPS4 ignoresflags. SharpProspero names 0x40SockInfoTimeWait("also list sockets in the TIME_WAIT state"); closed sockets leave the table at once here, so 0x40 lists the same sockets. I don't know what the console does with the other bits.guest_sce_netnow also checks the count, the full list against the per-socket records,n1, 0x40, the rejected flags and the IPv6 error. The description and the debt entry are updated.