SchOS/kernel/sys
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Nexoniarz a9ff1166b5 net: recvfrom says who sent it, and a datagram is delivered whole
The second of the two things the stack owed. recvfrom accepted the
address arguments and ignored them, so every caller was told nothing
about where a datagram came from -- which for UDP is most of the point:
a server that cannot see the sender cannot reply to it.

Fixing it properly meant fixing something worse that was sitting
underneath. UDP payloads went into the same byte ring TCP uses, with no
record of where one datagram ended and the next began, so two datagrams
that arrived together came back from one read as one. That is a bug
whose appearance depends on timing and whose blame lands on the sender.

Datagrams now carry a header alongside the bytes: source address, source
port, length. Sixteen of them per socket, in a ring beside the existing
one. Whole buffers would have been 16 sockets x 16 datagrams x an MTU of
static memory for something almost always empty; only the boundaries need
keeping, and those are eight bytes each. A datagram too big for the
buffer it is read into is truncated and the remainder discarded, rather
than left in the ring to be delivered as the head of the next one. One
that arrives with the queue full is dropped whole -- that is UDP's own
contract, and half a datagram in the ring would corrupt every one after.

An empty queue and a zero-length datagram are kept apart, because a
sender really can send zero bytes and the right answer to that is 0
rather than "nothing has arrived yet".

sendto grew the mirror image: a destination address on a datagram
socket, which is what a server replying to whoever just wrote to it
needs. On TCP a destination is ignored rather than refused -- the
connection decides where the bytes go, and programs pass one out of
habit. For a stream, recvfrom's source is read from the pcb: it is the
peer, and it is the same answer for every byte.

Verified: bootcheck -Net now covers UDP too, 45 [ok] and no failures.
The address check is real rather than cosmetic -- nettest deliberately
leaves its sockaddr uninitialised, so a kernel that filled in nothing
would print stack rubbish instead of 10.0.2.2 and the port the responder
is actually on. The boundaries are checked by byte count: the responder
sends 20 bytes and then 16, and the guest reports reading 20 and then
16. Treated as a stream the first read would have taken all 36.

Left for later, and deliberately: accept() still does not report the
peer's address, and getsockname/getpeername do not exist.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-15 16:23:06 +02:00
..
linux_abi.c Rename Schunix to SchOS; the kernel becomes SchIFT 2026-08-09 14:09:59 +02:00
sys_compat.c Rename Schunix to SchOS; the kernel becomes SchIFT 2026-08-09 14:09:59 +02:00
sys_fs.c schfs: the commit barrier, reflink, and attributes with an index over them 2026-08-15 16:02:02 +02:00
sys_mem.c Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
sys_net.c net: recvfrom says who sent it, and a datagram is delivered whole 2026-08-15 16:23:06 +02:00
sys_poll.c Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
sys_proc.c Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
sys_sig.c Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
sys_time.c Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
syscall.c Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
table.inc schfs: the commit barrier, reflink, and attributes with an index over them 2026-08-15 16:02:02 +02:00