libkernel: connect() to port 0 on an unconnected UDP socket succeeds where FreeBSD returns EADDRNOTAVAIL; fix branch ready #6880
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-16T15:45:29Z.
connect()to a destination with port 0 succeeds on an unconnected UDP socket and leaves a peer on port 0, so later sends go to a port that nothing can listen on. FreeBSD 11.4in_pcbconnect_setup(andin6_pcbconnectfor IPv6) fails withEADDRNOTAVAIL(49) when the destination port is 0, and the socket stays unconnected. TCP already returns 49 here.Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/kernel-socket-connect-port-zero (two commits on a recent main; it merges cleanly into current main:
libkernel/Socket/src/Udp.cppwith a newUnsetPort()helper, the new testtests/GuestSocketPortZero.cppregistered in the libkernelCMakeLists.txt, and a debt entry indocs/dev/debt/libkernel.md).connectnow returnsEADDRNOTAVAILfor a port-0 destination on an unconnected datagram socket, for IPv4 and IPv6. The first version also changedsendto/sendmsg; a review found it wrongly changed TCP results, so that part is gone and TCP behaves as on main.Checks:
connectto port 0 gives 49, a connected socket givesEISCONN(56), and a connectedsendtoto port 0 returns the byte count). The 27-test socket group passes.connectto port 0 on an unconnected, bound or disconnected UDP socket now returns 49 and leaves the socket unconnected (main returned 0 and left a peer on port 0);bindto port 0 is unchanged; the0.0.0.0and::port-0 cases still give 49 as on main.check_conventions.pyis clean andpr_overlap.pyfound no overlap; it also merges with thesendtofix filed as #5374, and the two do not interact.Not fixed here (listed in the debt entry):
connectto port 0 on an already connected UDP socket still returns 0 and keeps the peer (FreeBSD disconnects, fails with 49, andgetpeernamethen gives 57);sendtoto port 0 on an unconnected UDP socket still succeeds (FreeBSD returns 49, but it can succeed from a socket bound to a specific local address, so I left it); an address longer than 255 bytes with port 0 would return 49 instead ofENAMETOOLONGif #4920 lands. Only Windows was built and run.AI-assisted: yes