On Fri Jun 23 17:25:29 2023 +0000, Zebediah Figura wrote:
`sendto()` and `recvfrom()` are not currently special-cased for
AF_UNIX sockets, and they work correctly. They flow to the same functions as `send()` and `recv()` respectively, specifically `WS2_sendto()` and `WS2_recv_base()`. They don't work correctly if there's an address passed, though. Unless that address is ignored—for both functions—when TCP sockets are used, but we don't have tests for this, and if it is the case then that address conversion code is also unused and hence should just be removed.
Interesting. It seems the current implementations of those functions do not respect the following, from `sendto()`'s [documentation](https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-sendt...):
On a connection-oriented socket, the *to* and *tolen* parameters are ignored, making sendto equivalent to send.
Currently, if an address unsupported by ntdll's `sockaddr_to_unix` is passed to `sendto()`, `try_send()` returns `STATUS_ACCESS_VIOLATION`. If a `struct sockaddr` with a supported address family but invalid address is passed, the function works as expected, because `sendmsg()` returns `EISCONN` later and the address is zeroed out before retrying. This happens with any SOCK_STREAM socket. Windows ignores the entirety of both parameters, even if they are invalid (as does Linux).
The address conversion is needed and used for connectionless sockets (e.g. SOCK_DGRAM), and should therefore not be removed. However, the case for converting AF_UNIX sockets can be removed.
This is a broader bug with `sendto()` and `recvfrom()` and affects all SOCK_STREAM sockets. Should this be addressed in this patch or a separate one?