UDP(4)
π UDP(4) β like, the Internet User Datagram Protocol, bestie π
okay so this is the udp page from the Kernel Interfaces Manual β section 4, kernel interfaces, the whole vibe. sit down, grab a strawberry drink π, we're learning today.
β¨ NAME β¨
udp β the Internet User Datagram Protocol. yes THAT udp. the "fire and forget" one. she's iconic, she's unreliable, and we love her anyway π
π«Ά SYNOPSIS π«Ά
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int
socket(AF_INET, SOCK_DGRAM, 0);
literally that's it. that's the whole entrance. so clean, so demure β¨
πΈ DESCRIPTION πΈ
okay so first thing: UDP is a simple, unreliable datagram protocol, no cap. that's not me being mean, that's the actual spec, it's her whole brand π she exists to support the SOCK_DGRAM abstraction for the Internet protocol family.
UDP sockets are connectionless β like, she doesn't do commitment β and normally you use them with the sendto(2) and recvfrom(2) calls. but bestie, the connect(2) call can also be used to fix the destination for future packets. and in THAT case, you get to use the recv(2) or read(2) and send(2) or write(2) system calls. slay, options π
Now, the address formats: UDP addresses are identical to those used by TCP. specifically, UDP gives you a port identifier on top of the normal Internet address format. and listen β the UDP port space is separate from the TCP port space. i.e., a UDP port may not be βconnectedβ to a TCP port. two different girls, two different worlds π
Also! broadcast packets may be sent (assuming the underlying network supports this) by using a reserved βbroadcast addressβ β and that address is network interface dependent. so like, it's not one universal broadcast address, it's giving situationship with your NIC π
Options at the IP transport level may be used with UDP; 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>. one value. one. she's not flexible on this and honestly? respect π
π FIB support π
UDP sockets are FIB-aware π they inherit the FIB of the process which created the socket. main character energy, inheriting your whole situation from your creator.
By default, a UDP socket bound to an address can receive datagrams originating from any FIB. but if the net.inet.udp.bind_all_fibs tunable is set to 0, all UDP sockets will receive only datagrams originating from the same FIB as the socket. and in this mode, multiple sockets can be bound to the same address β so long as each socket belongs to a different FIB β similar to the behavior of the SO_REUSEPORT option. so yes, sharing is caring, but only across FIBs, iykyk π«Ά
β MIB (sysctl) Variables β
the udp protocol implements a number of variables in the net.inet.udp branch of the sysctl(3) MIB, which can also be read or modified with sysctl(8). she's got a whole little closet of settings π
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).) literally ghosting on purpose πchecksumβ enable UDP checksums (enabled by default). she's checking. always checking. π₯log_in_vainβ for all UDP datagrams, to ports on which there is no socket listening, log the connection attempt (disabled by default).maxdgramβ Maximum outgoing UDP datagram size. big girls only πrecvspaceβ Maximum space for incoming UDP datagrams.
π ERRORS π
A socket operation may fail with one of the following errors returned β yes, she has a whole roster of ways to say "no":
[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 ARE connected. sit DOWN π[ENOTCONN]β when trying to send a datagram, but no destination address is specified, and the socket has not been connected. she's lost. she has no address. she is simply vibing into the void π¦[ENOBUFS]β when the system runs out of memory for an internal data structure. the system is full bestie, there's no room π[EADDRINUSE]β when an attempt is made to create a socket with a port which has already been allocated. taken. occupied. not yours. π[EADDRNOTAVAIL]β when an attempt is made to create a socket with a network address for which no network interface exists. that address is not real, she made it up, it's giving delusion β¨
π¦ SEE ALSO π¦
getsockopt(2), recv(2), send(2), socket(2), blackhole(4), inet(4), intro(4), ip(4), udplite(4)
β the whole friend group, go say hi π
π HISTORY π
The udp protocol appeared in 4.2BSD. an OG. a legend. she was there and she's still here. periodt π
real talk though β remember she's unreliable. that's not a flaw, that's the design. if you need someone who texts back, that's a different protocol. don't come for her π«Ά
okay that's the whole page, mwah, go write some datagrams πβ¨π
signing off from the Debian edition of this page, dated January 20, 2025 β love u, mean it, see u in the next manpage π¦π
π¦ where this page comes from
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 1983, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms