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