libSceNet: sceNetListen on an unbound TCP socket fails with EINVAL on Windows; FreeBSD binds the wildcard address and succeeds; fix branch ready #5339
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 husseinkad on 2026-10-13T17:28:18Z.
sceNetListenon a TCP socket the guest never bound fails withEINVALon Windows, because Winsock requires a bound socket beforelisten. FreeBSD 11.4tcp_usr_listencallsin_pcbbindwhen the socket has no local port (inp_lport == 0), which binds the wildcard address with an ephemeral port, so the call succeeds. A server that callslistenfirst and then reads the port withgetsockname(a common way to get a free port) works on the console and fails here.Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/net-listen-autobind (two commits on a recent main: the change and a correction from review;
libSceNet/Export.cppandtests/GuestSceNet.cppwithCheckListenWithoutBindfor IPv4 and IPv6 andCheckListenAfterRefusedConnect).sceNetListennow binds the wildcard address of the socket's family first, unless the socket was already bound or already has a local port. The first version bound unconditionally and broke a case that worked on main: after a refused TCP connect, Winsock keeps an automatic local port, the extra bind failed withWSAEINVAL, andlistenreturnedEINVALwhere main (and FreeBSD) return 0.Checks:
CheckListenAfterRefusedConnectfails on the first version of the branch; both pass on the final head, 6 of 6 runs;guest_sce_netand the datagram tests pass.EINVAL), 50 concurrent listeners each got a distinct nonzero ephemeral port, andconnectandacceptto the auto-bound port work. Matches FreeBSD: a secondlistenreturns 0,listenon a UDP socket returnsEOPNOTSUPP,listenafter a failed bind (EADDRNOTAVAILorEADDRINUSE) returns 0, and backlogs 0, -1, 1, 128,INT_MAXandINT_MINall return 0.listenon a connected or accepted socket returnsEINVAL(main returned 0 orEBADF).check_conventions.pyis clean;pr_overlap.pyfinds only test-file overlap with #4669 and #4988 (same insertion points; theirExport.cpphunks are insceNetConnectandsceNetGetsockopt).Not covered: the Linux behaviour was read, not run (the host
listenalready auto-binds there). Only Windows was built and run.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T06:54:52Z.
Closing: no title is known to reach this, and functions are only changed when a title needs them. If a title stops on or misbehaves because of it on current main, comment here with the title ID and the log line.