xref: /freebsd/share/man/man4/udp.4 (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1.\" Copyright (c) 1983, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd August 1, 2022
29.Dt UDP 4
30.Os
31.Sh NAME
32.Nm udp
33.Nd Internet User Datagram Protocol
34.Sh SYNOPSIS
35.In sys/types.h
36.In sys/socket.h
37.In netinet/in.h
38.Ft int
39.Fn socket AF_INET SOCK_DGRAM 0
40.Sh DESCRIPTION
41.Tn UDP
42is a simple, unreliable datagram protocol which is used
43to support the
44.Dv SOCK_DGRAM
45abstraction for the Internet
46protocol family.
47.Tn UDP
48sockets are connectionless, and are
49normally used with the
50.Xr sendto 2
51and
52.Xr recvfrom 2
53calls, though the
54.Xr connect 2
55call may also be used to fix the destination for future
56packets (in which case the
57.Xr recv 2
58or
59.Xr read 2
60and
61.Xr send 2
62or
63.Xr write 2
64system calls may be used).
65.Pp
66.Tn UDP
67address formats are identical to those used by
68.Tn TCP .
69In particular
70.Tn UDP
71provides a port identifier in addition
72to the normal Internet address format.
73Note that the
74.Tn UDP
75port
76space is separate from the
77.Tn TCP
78port space (i.e., a
79.Tn UDP
80port
81may not be
82.Dq connected
83to a
84.Tn TCP
85port).
86In addition broadcast
87packets may be sent (assuming the underlying network supports
88this) by using a reserved
89.Dq broadcast address ;
90this address
91is network interface dependent.
92.Pp
93Options at the
94.Tn IP
95transport level may be used with
96.Tn UDP ;
97see
98.Xr ip 4 .
99.Tn UDP_ENCAP
100socket option may be used at the
101.Tn IPPROTO_UDP
102level to encapsulate
103.Tn ESP
104packets in
105.Tn UDP .
106Only one value is supported for this option:
107.Tn UDP_ENCAP_ESPINUDP
108from RFC 3948, defined in
109.In netinet/udp.h .
110.Sh MIB (sysctl) Variables
111The
112.Nm
113protocol implements a number of variables in the
114.Va net.inet.udp
115branch of the
116.Xr sysctl 3
117MIB, which can be also read or modified with
118.Xr sysctl 8 :
119.Bl -tag -width ".Va log_in_vain"
120.It Va blackhole
121When a datagram is received on a port where there is no socket
122listening, do not return an ICMP port unreachable message.
123(Disabled by default.
124See
125.Xr blackhole 4 . )
126.It Va checksum
127Enable UDP checksums (enabled by default).
128.It Va log_in_vain
129For all UDP datagrams, to ports on which there is no socket
130listening, log the connection attempt (disabled by default).
131.It Va maxdgram
132Maximum outgoing UDP datagram size
133.It Va recvspace
134Maximum space for incoming UDP datagrams
135.El
136.Sh ERRORS
137A socket operation may fail with one of the following errors returned:
138.Bl -tag -width Er
139.It Bq Er EISCONN
140when trying to establish a connection on a socket which
141already has one, or when trying to send a datagram with the destination
142address specified and the socket is already connected;
143.It Bq Er ENOTCONN
144when trying to send a datagram, but
145no destination address is specified, and the socket has not been
146connected;
147.It Bq Er ENOBUFS
148when the system runs out of memory for
149an internal data structure;
150.It Bq Er EADDRINUSE
151when an attempt
152is made to create a socket with a port which has already been
153allocated;
154.It Bq Er EADDRNOTAVAIL
155when an attempt is made to create a
156socket with a network address for which no network interface
157exists.
158.El
159.Sh SEE ALSO
160.Xr getsockopt 2 ,
161.Xr recv 2 ,
162.Xr send 2 ,
163.Xr socket 2 ,
164.Xr blackhole 4 ,
165.Xr inet 4 ,
166.Xr intro 4 ,
167.Xr ip 4 ,
168.Xr udplite 4
169.Sh HISTORY
170The
171.Nm
172protocol appeared in
173.Bx 4.2 .
174