1.\" $NetBSD: udp.4,v 1.10 2003/08/07 10:31:04 agc 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 June 5, 1993 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 97Options at the 98.Tn IP 99transport level may be used with 100.Tn UDP ; 101see 102.Xr ip 4 103or 104.Xr ip6 4 . 105.Sh DIAGNOSTICS 106A socket operation may fail with one of the following errors returned: 107.Bl -tag -width [EADDRNOTAVAIL] 108.It Bq Er EISCONN 109when trying to establish a connection on a socket which 110already has one, or when trying to send a datagram with the destination 111address specified and the socket is already connected; 112.It Bq Er ENOTCONN 113when trying to send a datagram, but 114no destination address is specified, and the socket hasn't been 115connected; 116.It Bq Er ENOBUFS 117when the system runs out of memory for 118an internal data structure; 119.It Bq Er EADDRINUSE 120when an attempt 121is made to create a socket with a port which has already been 122allocated; 123.It Bq Er EADDRNOTAVAIL 124when an attempt is made to create a socket with a network address 125for which no network interface exists. 126.El 127.Sh SEE ALSO 128.Xr getsockopt 2 , 129.Xr recv 2 , 130.Xr send 2 , 131.Xr socket 2 , 132.Xr inet 4 , 133.Xr inet6 4 , 134.Xr intro 4 , 135.Xr ip 4 , 136.Xr ip6 4 137.Rs 138.%R RFC 139.%N 768 140.%D August 28, 1980 141.%T "User Datagram Protocol" 142.Re 143.Rs 144.%R RFC 145.%N 1122 146.%D October 1989 147.%T "Requirements for Internet Hosts -- Communication Layers" 148.Re 149.Sh HISTORY 150The 151.Nm 152protocol appeared in 153.Bx 4.2 . 154