xref: /freebsd/share/man/man4/udp.4 (revision 17ee9d00bc1ae1e598c38f25826f861e4bc6c3ce)
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. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)udp.4	8.1 (Berkeley) 6/5/93
33.\"
34.Dd June 5, 1993
35.Dt UDP 4
36.Os BSD 4.2
37.Sh NAME
38.Nm udp
39.Nd Internet User Datagram Protocol
40.Sh SYNOPSIS
41.Fd #include <sys/socket.h>
42.Fd #include <netinet/in.h>
43.Ft int
44.Fn socket AF_INET 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
56and
57.Xr recvfrom
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.  Note that the
78.Tn UDP
79port
80space is separate from the
81.Tn TCP
82port space (i.e. a
83.Tn UDP
84port
85may not be
86.Dq connected
87to a
88.Tn TCP
89port).  In addition broadcast
90packets may be sent (assuming the underlying network supports
91this) by using a reserved
92.Dq broadcast address ;
93this address
94is network interface dependent.
95.Pp
96Options at the
97.Tn IP
98transport level may be used with
99.Tn UDP ;
100see
101.Xr ip 4 .
102.Sh DIAGNOSTICS
103A socket operation may fail with one of the following errors returned:
104.Bl -tag -width [EADDRNOTAVAIL]
105.It Bq Er EISCONN
106when trying to establish a connection on a socket which
107already has one, or when trying to send a datagram with the destination
108address specified and the socket is already connected;
109.It Bq Er ENOTCONN
110when trying to send a datagram, but
111no destination address is specified, and the socket hasn't been
112connected;
113.It Bq Er ENOBUFS
114when the system runs out of memory for
115an internal data structure;
116.It Bq Er EADDRINUSE
117when an attempt
118is made to create a socket with a port which has already been
119allocated;
120.It Bq Er EADDRNOTAVAIL
121when an attempt is made to create a
122socket with a network address for which no network interface
123exists.
124.El
125.Sh SEE ALSO
126.Xr getsockopt 2 ,
127.Xr recv 2 ,
128.Xr send 2 ,
129.Xr socket 2 ,
130.Xr intro 4 ,
131.Xr inet 4 ,
132.Xr ip 4
133.Sh HISTORY
134The
135.Nm
136protocol appeared in
137.Bx 4.2 .
138