UDPREAD(3)

πŸ“¦ version 0_git20260208, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

πŸ’– UDPREAD(3) πŸ’–

okay bestie, welcome to UDPREAD(3) from the Library Functions Manual β€” the section 3 library-call zone. this page is about udpread and udpwrite, aka reading and writing UDP packets, and it’s honestly a little iconic. πŸ¦‹

✨ NAME ✨

  • udpread, udpwrite β€” read and write UDP packets, no cap. πŸ’…

🌸 SYNOPSIS 🌸

here’s the exact setup, bestie β€” copy it like your life depends on it:

#include <u.h>

#include <libc.h>

#include <ip.h>

typedef struct Udphdr Udphdr;
struct Udphdr
{
    uchar   raddr[IPaddrlen];/* remote address and port */
    uchar   laddr[IPaddrlen];/* local address and port */
    uchar   rport[2];
    uchar   lport[2];
};

long        udpread(int fd, Udphdr *hdr, void *data, long n)

long udpwrite(int fd, Udphdr *hdr, void *data, long n)

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so udpread and udpwrite read and write UDP packets from the UDP network connection established on file descriptor fd. that’s lowkey the whole main-character situation. ✨

  • udpread reads at most n bytes of packet body into data, stores the header in hdr, and returns the number of bytes stored in data. she’s giving β€œread the packet, keep the header, count the bytes.” πŸŽ€
  • udpwrite writes the n bytes stored in data in a UDP packet with header hdr. that’s it, that’s the write. πŸ’Œ
🚨 important vibe check: the Udphdr frames the addresses as local and remote instead of source and destination. so the hdr filled in for a packet read by udpread can be used unchanged in udpwrite to send a response back to the sender of the original packet. like, the header you got from reading? you can literally reuse it to clap back at the sender. periodt. πŸ’…

🌈 SOURCE 🌈

/src/lib9/udp.c

πŸŽ€ SEE ALSO πŸŽ€

  • ip(3) β€” go read that too, bestie. 🫢

mwah πŸ’‹ β€” this has been UDPREAD(3), Library Functions Manual edition, source file /src/lib9/udp.c; no date listed, and that’s the cute little sign-off. πŸ’–