libkernel: sendto to port 0 from an unbound IPv4 datagram socket is sent where FreeBSD 11.4 fails with EADDRNOTAVAIL #8498

Closed
opened 2026-10-20 13:57:12 +00:00 by xXPBSXx · 0 comments
xXPBSXx commented 2026-10-20 13:57:12 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T13:57:12Z.


Repro

Any host. s = socket(AF_INET, SOCK_DGRAM, 0) (not bound, not connected), sendto(s, "x", 1, 0, {127.0.0.1, port 0}, 16).
Expected (FreeBSD 11.4): -1/EADDRNOTAVAIL (49). udp_output hands the destination to in_pcbconnect_setup unless the socket is bound to a specific address and port and the destination is neither INADDR_ANY nor INADDR_BROADCAST; in_pcbconnect_setup fails sin_port == 0 with EADDRNOTAVAIL (sys/netinet/in_pcb.c:1034).
Actual: the datagram is sent (result 1). connect to port 0 already fails with 49 (#6884); docs/dev/debt/libkernel.md lists the sendto/sendmsg case as a known gap.
Test: core/libs/tests/GuestUdp.cpp (CheckSendToPortZero, new; aborts before the fix).
Fix branch: https://github.com/xXPBSXx/AnyPS5/tree/fix/sendto-port-zero
AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5942985449 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8498). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T13:57:12Z. --- ### Repro Any host. `s = socket(AF_INET, SOCK_DGRAM, 0)` (not bound, not connected), `sendto(s, "x", 1, 0, {127.0.0.1, port 0}, 16)`. Expected (FreeBSD 11.4): -1/EADDRNOTAVAIL (49). `udp_output` hands the destination to `in_pcbconnect_setup` unless the socket is bound to a specific address and port and the destination is neither INADDR_ANY nor INADDR_BROADCAST; `in_pcbconnect_setup` fails `sin_port == 0` with `EADDRNOTAVAIL` (sys/netinet/in_pcb.c:1034). Actual: the datagram is sent (result 1). `connect` to port 0 already fails with 49 (#6884); docs/dev/debt/libkernel.md lists the `sendto`/`sendmsg` case as a known gap. Test: `core/libs/tests/GuestUdp.cpp` (`CheckSendToPortZero`, new; aborts before the fix). Fix branch: https://github.com/xXPBSXx/AnyPS5/tree/fix/sendto-port-zero AI-assisted (Claude Code).
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#8498
No description provided.