libkernel: send and sendto without a destination on an unconnected UDP socket return ENOTCONN (Windows) or EIO (Linux), where FreeBSD returns EDESTADDRREQ #3113

Closed
opened 2026-10-10 22:28:43 +00:00 by husseinkad · 2 comments
husseinkad commented 2026-10-10 22:28:43 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-10T22:28:43Z.


What

send, sendto without an address, sendmsg without a name and write on an unconnected UDP guest socket (core/libs/prx/libkernel/Socket/src/Udp.cpp) return ENOTCONN (57) on Windows (Winsock's WSAENOTCONN) and EIO (5) on Linux, where the host's EDESTADDRREQ has no mapping in NativeError(). FreeBSD's sosend_dgram (sys/kern/uipc_socket.c) returns EDESTADDRREQ (39) for a datagram socket without a connected peer or address; ENOTCONN there is only for protocols with PR_CONNREQUIRED such as TCP, which stays as it is (sys/sys/errno.h: EDESTADDRREQ 39, ENOTCONN 57). The send(2) man page lists only ENOTCONN (for connection-mode sockets), so the source is the reference.

Reproduce

Windows 11, WinLibs GCC 15.2.0 r7, main at the time of writing: create a UDP socket without connect, call send(sock, buf, 1, 0) or sendto(sock, buf, 1, 0, NULL, 0): -1 with errno 57 (FreeBSD: 39).

Fix

A tested fix is on my fork: husseinkad:fix/net-udp-errno (one commit on main; PR #2694, closed by the intake check): NativeError() maps WSAEDESTADDRREQ and EDESTADDRREQ to 39, and a new SendError(type) maps WSAENOTCONN to 39 for datagram sockets; send and sendto use it, and sendmsg and Write go through them. guest_udp gains send and sendto(NULL, 0) on the unconnected sender and fails without the change.

Checked with a loopback probe through the guest exports against main's Udp.cpp built into a second libkernel: 554 cases per build (UDP4/UDP6 unbound, bound and connected, blocking and nonblocking, send/sendto/sendmsg/write, the receive family, getpeername, shutdown, 70,000-byte payloads, TCP in every state, socketpairs, closed descriptors): the only differences are ENOTCONN becoming EDESTADDRREQ on UDP sockets with no connected peer; TCP, connected UDP, socketpair, recv*, getpeername and shutdown results are identical. The Linux branch is reviewed from the diff only. Three older, separate divergences in the same send path were noted and left alone: sendto with a NULL address and non-zero length returns EINVAL, a very short address returns EFAULT (FreeBSD EINVAL), and a send on an unconnected TCP socket on Linux returns EPIPE instead of ENOTCONN.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5795847739 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3113). Originally posted by [husseinkad](https://github.com/husseinkad) on 2026-10-10T22:28:43Z. --- ### What `send`, `sendto` without an address, `sendmsg` without a name and `write` on an unconnected UDP guest socket (`core/libs/prx/libkernel/Socket/src/Udp.cpp`) return `ENOTCONN` (57) on Windows (Winsock's `WSAENOTCONN`) and `EIO` (5) on Linux, where the host's `EDESTADDRREQ` has no mapping in `NativeError()`. FreeBSD's `sosend_dgram` (`sys/kern/uipc_socket.c`) returns `EDESTADDRREQ` (39) for a datagram socket without a connected peer or address; `ENOTCONN` there is only for protocols with `PR_CONNREQUIRED` such as TCP, which stays as it is (`sys/sys/errno.h`: `EDESTADDRREQ` 39, `ENOTCONN` 57). The send(2) man page lists only `ENOTCONN` (for connection-mode sockets), so the source is the reference. ### Reproduce Windows 11, WinLibs GCC 15.2.0 r7, `main` at the time of writing: create a UDP socket without `connect`, call `send(sock, buf, 1, 0)` or `sendto(sock, buf, 1, 0, NULL, 0)`: `-1` with `errno` 57 (FreeBSD: 39). ### Fix A tested fix is on my fork: [`husseinkad:fix/net-udp-errno`](https://github.com/husseinkad/AnyPS5/tree/fix/net-udp-errno) (one commit on `main`; PR #2694, closed by the intake check): `NativeError()` maps `WSAEDESTADDRREQ` and `EDESTADDRREQ` to 39, and a new `SendError(type)` maps `WSAENOTCONN` to 39 for datagram sockets; `send` and `sendto` use it, and `sendmsg` and `Write` go through them. `guest_udp` gains `send` and `sendto(NULL, 0)` on the unconnected sender and fails without the change. Checked with a loopback probe through the guest exports against `main`'s `Udp.cpp` built into a second `libkernel`: 554 cases per build (UDP4/UDP6 unbound, bound and connected, blocking and nonblocking, send/sendto/sendmsg/write, the receive family, `getpeername`, `shutdown`, 70,000-byte payloads, TCP in every state, socketpairs, closed descriptors): the only differences are `ENOTCONN` becoming `EDESTADDRREQ` on UDP sockets with no connected peer; TCP, connected UDP, socketpair, `recv*`, `getpeername` and `shutdown` results are identical. The Linux branch is reviewed from the diff only. Three older, separate divergences in the same send path were noted and left alone: `sendto` with a `NULL` address and non-zero length returns `EINVAL`, a very short address returns `EFAULT` (FreeBSD `EINVAL`), and a send on an unconnected TCP socket on Linux returns `EPIPE` instead of `ENOTCONN`. AI-assisted: yes.
hikazey commented 2026-10-11 19:16:02 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by hikazey on 2026-10-11T19:16:02Z.


Linux check, since the Linux side was reviewed from the diff only: fix/net-udp-errno (8efd5ec7) merged onto main 06da1176, Ubuntu 24.04 container, GCC 14.2, Release with CI's configure flags.

build guest_udp
this branch 5/5 passed
Udp.cpp reverted to main, test kept 5/5 failed
full suite with this branch 749/752 passed

So the EDESTADDRREQ → 39 mapping does what the test expects on Linux. The three full-suite failures fail the same way on plain main in this container and come from the setup: import_audit needs git inside the container, and agc_driver_flat_apertures and agc_driver_image_packed16_load run on llvmpipe.

One heads-up for whoever opens the PR: on current main (a11c8f7f7) Udp.cpp still merges cleanly, but GuestUdp.cpp now conflicts after d78af2c71 and b4a59e34c touched the socket tests.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6112710787 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3113#issuecomment-6112710787). Originally posted by [hikazey](https://github.com/hikazey) on 2026-10-11T19:16:02Z. --- Linux check, since the Linux side was reviewed from the diff only: `fix/net-udp-errno` (`8efd5ec7`) merged onto `main` `06da1176`, Ubuntu 24.04 container, GCC 14.2, Release with CI's configure flags. | build | `guest_udp` | | --- | --- | | this branch | 5/5 passed | | `Udp.cpp` reverted to `main`, test kept | 5/5 failed | | full suite with this branch | 749/752 passed | So the `EDESTADDRREQ` → 39 mapping does what the test expects on Linux. The three full-suite failures fail the same way on plain `main` in this container and come from the setup: `import_audit` needs `git` inside the container, and `agc_driver_flat_apertures` and `agc_driver_image_packed16_load` run on llvmpipe. One heads-up for whoever opens the PR: on current `main` (`a11c8f7f7`) `Udp.cpp` still merges cleanly, but `GuestUdp.cpp` now conflicts after d78af2c71 and b4a59e34c touched the socket tests. AI-assisted: yes (Claude Code).
husseinkad commented 2026-10-11 19:25:14 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-11T19:25:14Z.


Thank you @hikazey for the Linux run and for the heads-up about GuestUdp.cpp. I rebased the change onto current main: https://github.com/husseinkad/AnyPS5/tree/fix/net-udp-errno-rebased (6c0295d3a). The conflict was in the test, which now connects sender earlier, so the unaddressed-send checks use a fresh unconnected socket. On Windows guest_udp passes with the change and fails with Udp.cpp reverted to main; guest_tcp, guest_socket_read_write and guest_socket_pair pass.

Note that #3592 (the socket errno table from #3573) now covers the WSAEDESTADDRREQ and EDESTADDRREQ mapping in NativeError(), so after it merges the only part left here is SendError, the Windows WSAENOTCONN → 39 case for an unconnected datagram send/sendto. pr_overlap lists #3592 on Udp.cpp for that reason.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6112801190 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3113#issuecomment-6112801190). Originally posted by [husseinkad](https://github.com/husseinkad) on 2026-10-11T19:25:14Z. --- Thank you @hikazey for the Linux run and for the heads-up about `GuestUdp.cpp`. I rebased the change onto current `main`: https://github.com/husseinkad/AnyPS5/tree/fix/net-udp-errno-rebased (`6c0295d3a`). The conflict was in the test, which now connects `sender` earlier, so the unaddressed-send checks use a fresh unconnected socket. On Windows `guest_udp` passes with the change and fails with `Udp.cpp` reverted to `main`; `guest_tcp`, `guest_socket_read_write` and `guest_socket_pair` pass. Note that #3592 (the socket errno table from #3573) now covers the `WSAEDESTADDRREQ` and `EDESTADDRREQ` mapping in `NativeError()`, so after it merges the only part left here is `SendError`, the Windows `WSAENOTCONN` → 39 case for an unconnected datagram `send`/`sendto`. `pr_overlap` lists #3592 on `Udp.cpp` for that reason. AI-assisted: yes
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#3113
No description provided.