UDPREAD(3)
π 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. β¨
udpreadreads at mostnbytes of packet body intodata, stores the header inhdr, and returns the number of bytes stored indata. sheβs giving βread the packet, keep the header, count the bytes.β πudpwritewrites thenbytes stored indatain a UDP packet with headerhdr. thatβs it, thatβs the write. π
π¨ important vibe check: theUdphdrframes the addresses as local and remote instead of source and destination. so thehdrfilled in for a packet read byudpreadcan be used unchanged inudpwriteto 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. π
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms