1.\" $NetBSD: udp.4,v 1.14 2012/11/12 05:13:28 christos 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 20, 2012 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 are two valid encapsulation options: 115.Tn UDP_ENCAP_ESPINUDP_NON_IKE 116from draft-ietf-ipsec-nat-t-ike-00/01 and 117.Tn UDP_ENCAP_ESPINUDP 118from draft-ietf-ipsec-udp-encaps-06 119defined in 120.In netinet/udp.h . 121.Pp 122Options at the 123.Tn IP 124transport level may be used with 125.Tn UDP ; 126see 127.Xr ip 4 128or 129.Xr ip6 4 . 130.Sh DIAGNOSTICS 131A socket operation may fail with one of the following errors returned: 132.Bl -tag -width [EADDRNOTAVAIL] 133.It Bq Er EISCONN 134when trying to establish a connection on a socket which 135already has one, or when trying to send a datagram with the destination 136address specified and the socket is already connected; 137.It Bq Er ENOTCONN 138when trying to send a datagram, but 139no destination address is specified, and the socket hasn't been 140connected; 141.It Bq Er ENOBUFS 142when the system runs out of memory for 143an internal data structure; 144.It Bq Er EADDRINUSE 145when an attempt 146is made to create a socket with a port which has already been 147allocated; 148.It Bq Er EADDRNOTAVAIL 149when an attempt is made to create a socket with a network address 150for which no network interface exists. 151.El 152.Sh SEE ALSO 153.Xr getsockopt 2 , 154.Xr recv 2 , 155.Xr send 2 , 156.Xr socket 2 , 157.Xr inet 4 , 158.Xr inet6 4 , 159.Xr intro 4 , 160.Xr ip 4 , 161.Xr ip6 4 , 162.Xr rfc6056 7 , 163.Xr sysctl 7 164.Rs 165.%R RFC 166.%N 768 167.%D August 28, 1980 168.%T "User Datagram Protocol" 169.Re 170.Rs 171.%R RFC 172.%N 1122 173.%D October 1989 174.%T "Requirements for Internet Hosts -- Communication Layers" 175.Re 176.Sh HISTORY 177The 178.Nm 179protocol appeared in 180.Bx 4.2 . 181