xref: /openbsd-src/share/man/man4/udp.4 (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1.\"	$OpenBSD: udp.4,v 1.8 2000/12/21 21:01:21 aaron 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
61and
62.Xr recvfrom
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.  Note that the
83.Tn UDP
84port
85space is separate from the
86.Tn TCP
87port space (i.e. a
88.Tn UDP
89port
90may not be
91.Dq connected
92to a
93.Tn TCP
94port).  In addition broadcast
95packets may be sent (assuming the underlying network supports
96this) by using a reserved
97.Dq broadcast address ;
98this address
99is network interface dependent.
100.Pp
101Options at the
102.Tn IP
103transport level may be used with
104.Tn UDP ;
105see
106.Xr ip 4
107or
108.Xr ip6 4 .
109.Sh DIAGNOSTICS
110A socket operation may fail with one of the following errors returned:
111.Bl -tag -width [EADDRNOTAVAIL]
112.It Bq Er EISCONN
113when trying to establish a connection on a socket which
114already has one, or when trying to send a datagram with the destination
115address specified and the socket is already connected;
116.It Bq Er ENOTCONN
117when trying to send a datagram, but
118no destination address is specified, and the socket hasn't been
119connected;
120.It Bq Er ENOBUFS
121when the system runs out of memory for
122an internal data structure;
123.It Bq Er EADDRINUSE
124when an attempt
125is made to create a socket with a port which has already been
126allocated;
127.It Bq Er EADDRNOTAVAIL
128when an attempt is made to create a
129socket with a network address for which no network interface
130exists.
131.El
132.Sh SEE ALSO
133.Xr getsockopt 2 ,
134.Xr recv 2 ,
135.Xr send 2 ,
136.Xr socket 2 ,
137.Xr inet 4 ,
138.Xr inet6 4 ,
139.Xr ip 4 ,
140.Xr ip6 4 ,
141.Xr netintro 4
142.Sh HISTORY
143The
144.Nm
145protocol appeared in
146.Bx 4.2 .
147