libkernel: connect() on a listening TCP socket returns the host error instead of EOPNOTSUPP; fix branch ready #6923
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-16T18:54:22Z.
connect()on a listening TCP socket returns the host error (EINVALon Windows,EISCONNon Linux) instead ofEOPNOTSUPP(45). FreeBSD 11.4soconnectatfails any socket that hasSO_ACCEPTCONNset withEOPNOTSUPP. A program that connects its own listener (a probe, or a retry loop that reuses the descriptor) tests for 45 on the console and sees a different number here.Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/socket-connect-listener-eopnotsupp (two commits; it merges cleanly into current main;
libkernel/Socket/src/Udp.cpp, the new testtests/GuestSocketConnectListening.cppregistered in the libkernelCMakeLists.txt). For stream sockets,connectnow queriesSO_ACCEPTCONNafter the address has been read and validated (FreeBSD'skern_connectcopies the address in beforesoconnect, so a null or short address still fails first) and returnsEOPNOTSUPPfor a listener, before the family check.Checks:
shutdown;connect(listener, NULL, 16)gives 14 and a one-byte address gives the same error as a plain socket, as in FreeBSD's order. Non-listening TCP is unchanged (NULL gives 14, a refused connect gives 61, a second connect gives 56, and a connect to the listener from another socket works), and UDP is unchanged.acceptkeeps working after every failed connect on the listener. In a 3,000-sequence fuzz, 351 connect results changed from main (156 from 22, 147 from 47, 48 from 14), all on listeners.check_conventions.pyis clean andpr_overlap.pyfound no overlap; it conflicts only textually (adjacent insertions) with mylistenauto-bind fix and the port-zero fix, and keeping both sides resolves it.Not covered: addresses that
Address()rejects with 47 (anAF_UNIXfamily byte, family 0 or 255, a 4-byte-long IPv4 address) still return 47 on a listener where FreeBSD would return 45; a length of 1 returns 14 for plain and listening sockets where FreeBSD givesEINVAL(22), which the sockaddr length checks in #4920 would change. The Linux error code was read from the kernel source, not run. Only Windows was built and run.AI-assisted: yes