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