UDP(4)
π UDP(4) β the kernel interfaces manual, but make it cute
okay bestie, pull up a chair, we're talking about udp β Internet User Datagram Protocol. this is a page from the Kernel Interfaces Manual and it's genuinely iconic, no cap. π
β¨ NAME β¨
udp β Internet User Datagram Protocol π¦
πΈ SYNOPSIS πΈ
the way you summon one is literally just:
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int
socket(AF_INET, SOCK_DGRAM, 0);
look at her. three includes and a socket() call. lowkey elegant. π
π DESCRIPTION π
so. UDP is a simple, unreliable datagram protocol and her whole job is supporting the SOCK_DGRAM abstraction for the Internet protocol family. simple! unreliable! unbothered! π
UDP sockets are connectionless, and they're normally used with the sendto(2) and recvfrom(2) calls β though the connect(2) call may also be used to fix the destination for future packets. and if you do that, you get to use recv(2) or read(2) and send(2) or write(2) system calls instead. main character flexibility, honestly. β¨
UDP address formats are identical to those used by TCP. in particular, UDP provides a port identifier on top of the normal Internet address format. and here's the tea, bestie:
note that the UDP port space is separate from the TCP port space β i.e., a UDP port may not be "connected" to a TCP port. π
also you can send broadcast packets (assuming the underlying network supports this, don't come for me) by using a reserved "broadcast address" β and that address is network interface dependent. iykyk. π
options at the IP transport level may be used with UDP; go see ip(4). and the UDP_ENCAP socket option may be used at the IPPROTO_UDP level to encapsulate ESP packets in UDP. only one value is supported for this option: UDP_ENCAP_ESPINUDP from RFC 3948, defined in <netinet/udp.h>. that's it. one value. she said pick one and i did. π«Ά
π MIB VARIABLES π
the udp protocol implements a number of variables in the net.inet branch of the sysctl(3) MIB. slay. here's the whole roster, bestie, no skipping:
UDPCTL_CHECKSUM(udp.checksum) β enable udp checksums. enabled by default, as she should be. βUDPCTL_MAXDGRAM(udp.maxdgram) β maximum outgoing UDP datagram size. πUDPCTL_RECVSPACE(udp.recvspace) β maximum space for incoming UDP datagrams. π₯udp.log_in_vainβ for all udp datagrams sent to ports on which there is no socket listening, log the connection attempt. disabled by default β it's giving "you're not on the guest list". πudp.blackholeβ when a datagram is received on a port where there is no socket listening, do not return an ICMP port unreachable message. disabled by default. seeblackhole(4)for the lore. π³οΈ
π ERRORS π
a socket operation may fail with one of the following errors returned. brace yourself, this is the vibe check section:
[EISCONN]β when trying to establish a connection on a socket which already has one, or when trying to send a datagram with the destination address specified and the socket is already connected. girl you're already taken!! π[ENOTCONN]β when trying to send a datagram, but no destination address is specified, and the socket has not been connected. you cannot send a message with no address bestie, that's not how this works π[ENOBUFS]β when the system runs out of memory for an internal data structure. not her fault, she's just full π₯Ί[EADDRINUSE]β when an attempt is made to create a socket with a port which has already been allocated. that port is TAKEN. find your own. π[EADDRNOTAVAIL]β when an attempt is made to create a socket with a network address for which no network interface exists. that address does not exist, she's imaginary, she's a ghost π»
π SEE ALSO π
go read these next, they're all bangers: getsockopt(2), recv(2), send(2), socket(2), blackhole(4), inet(4), intro(4), ip(4), udplite(4). β¨
π¦ HISTORY π¦
the udp protocol appeared in 4.2BSD. an OG. a legend. a founding mother. π
and that's the whole page bestie β this version of UDP(4) comes to you from Debian, dated February 6, 2017. π thanks for reading, go forth and send some datagrams, unreliably and with confidence. periodt. β¨π«Ά
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1983, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms