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. Neither the name of the University nor the names of its contributors 13.\" may be used to endorse or promote products derived from this software 14.\" without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.\" @(#)udp.4 8.1 (Berkeley) 6/5/93 29.\" $FreeBSD: src/share/man/man4/udp.4,v 1.8.2.4 2001/12/17 11:30:12 ru Exp $ 30.\" $DragonFly: src/share/man/man4/udp.4,v 1.2 2003/06/17 04:36:59 dillon Exp $ 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/types.h 40.In sys/socket.h 41.In netinet/in.h 42.Ft int 43.Fn socket AF_INET SOCK_DGRAM 0 44.Sh DESCRIPTION 45.Tn UDP 46is a simple, unreliable datagram protocol which is used 47to support the 48.Dv SOCK_DGRAM 49abstraction for the Internet 50protocol family. 51.Tn UDP 52sockets are connectionless, and are 53normally used with the 54.Xr sendto 2 55and 56.Xr recvfrom 2 57calls, though the 58.Xr connect 2 59call may also be used to fix the destination for future 60packets (in which case the 61.Xr recv 2 62or 63.Xr read 2 64and 65.Xr send 2 66or 67.Xr write 2 68system calls may be used). 69.Pp 70.Tn UDP 71address formats are identical to those used by 72.Tn TCP . 73In particular 74.Tn UDP 75provides a port identifier in addition 76to the normal Internet address format. Note that the 77.Tn UDP 78port 79space is separate from the 80.Tn TCP 81port space (i.e. a 82.Tn UDP 83port 84may not be 85.Dq connected 86to a 87.Tn TCP 88port). In addition broadcast 89packets may be sent (assuming the underlying network supports 90this) by using a reserved 91.Dq broadcast address ; 92this address 93is network interface dependent. 94.Pp 95Options at the 96.Tn IP 97transport level may be used with 98.Tn UDP ; 99see 100.Xr ip 4 . 101.Sh ERRORS 102A socket operation may fail with one of the following errors returned: 103.Bl -tag -width Er 104.It Bq Er EISCONN 105when trying to establish a connection on a socket which 106already has one, or when trying to send a datagram with the destination 107address specified and the socket is already connected; 108.It Bq Er ENOTCONN 109when trying to send a datagram, but 110no destination address is specified, and the socket hasn't been 111connected; 112.It Bq Er ENOBUFS 113when the system runs out of memory for 114an internal data structure; 115.It Bq Er EADDRINUSE 116when an attempt 117is made to create a socket with a port which has already been 118allocated; 119.It Bq Er EADDRNOTAVAIL 120when an attempt is made to create a 121socket with a network address for which no network interface 122exists. 123.El 124.Sh MIB VARIABLES 125The 126.Nm 127protocol implements a number of variables in the 128.Li net.inet 129branch of the 130.Xr sysctl 3 131MIB. 132.Bl -tag -width UDPCTL_RECVSPACEX 133.It UDPCTL_CHECKSUM 134.Pq udp.checksum 135Enable udp checksums (enabled by default). 136.It UDPCTL_MAXDGRAM 137.Pq udp.maxdgram 138Maximum outgoing UDP datagram size 139.It UDPCTL_RECVSPACE 140.Pq udp.recvspace 141Maximum space for incoming UDP datagrams 142.It udp.log_in_vain 143For all udp datagrams, to ports on which there is no socket 144listening, log the connection attempt (disabled by default). 145.It udp.blackhole 146When a datagram is received on a port where there is no socket 147listening, do not return an ICMP port unreachable message. 148(Disabled by default. See 149.Xr blackhole 4 . ) 150.El 151.Sh SEE ALSO 152.Xr getsockopt 2 , 153.Xr recv 2 , 154.Xr send 2 , 155.Xr socket 2 , 156.Xr blackhole 4 , 157.Xr inet 4 , 158.Xr intro 4 , 159.Xr ip 4 160.Sh HISTORY 161The 162.Nm 163protocol appeared in 164.Bx 4.2 . 165