1.\" Copyright (c) 1983, 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)udp.4 6.5 (Berkeley) 03/28/91 7.\" 8.Dd 9.Dt UDP 4 10.Os BSD 4.2 11.Sh NAME 12.Nm udp 13.Nd Internet User Datagram Protocol 14.Sh SYNOPSIS 15.Fd #include <sys/socket.h> 16.Fd #include <netinet/in.h> 17.Ft int 18.Fn socket AF_INET SOCK_DGRAM 0 19.Sh DESCRIPTION 20.Tn UDP 21is a simple, unreliable datagram protocol which is used 22to support the 23.Dv SOCK_DGRAM 24abstraction for the Internet 25protocol family. 26.Tn UDP 27sockets are connectionless, and are 28normally used with the 29.Xr sendto 30and 31.Xr recvfrom 32calls, though the 33.Xr connect 2 34call may also be used to fix the destination for future 35packets (in which case the 36.Xr recv 2 37or 38.Xr read 2 39and 40.Xr send 2 41or 42.Xr write 2 43system calls may be used). 44.Pp 45.Tn UDP 46address formats are identical to those used by 47.Tn TCP . 48In particular 49.Tn UDP 50provides a port identifier in addition 51to the normal Internet address format. Note that the 52.Tn UDP 53port 54space is separate from the 55.Tn TCP 56port space (i.e. a 57.Tn UDP 58port 59may not be 60.Dq connected 61to a 62.Tn TCP 63port). In addition broadcast 64packets may be sent (assuming the underlying network supports 65this) by using a reserved 66.Dq broadcast address ; 67this address 68is network interface dependent. 69.Pp 70Options at the 71.Tn IP 72transport level may be used with 73.Tn UDP ; 74see 75.Xr ip 4 . 76.Sh DIAGNOSTICS 77A socket operation may fail with one of the following errors returned: 78.Bl -tag -width [EADDRNOTAVAIL] 79.It Bq Er EISCONN 80when trying to establish a connection on a socket which 81already has one, or when trying to send a datagram with the destination 82address specified and the socket is already connected; 83.It Bq Er ENOTCONN 84when trying to send a datagram, but 85no destination address is specified, and the socket hasn't been 86connected; 87.It Bq Er ENOBUFS 88when the system runs out of memory for 89an internal data structure; 90.It Bq Er EADDRINUSE 91when an attempt 92is made to create a socket with a port which has already been 93allocated; 94.It Bq Er EADDRNOTAVAIL 95when an attempt is made to create a 96socket with a network address for which no network interface 97exists. 98.El 99.Sh SEE ALSO 100.Xr getsockopt 2 , 101.Xr recv 2 , 102.Xr send 2 , 103.Xr socket 2 , 104.Xr intro 4 , 105.Xr inet 4 , 106.Xr ip 4 107.Sh HISTORY 108The 109.Nm 110protocol appeared in 111.Bx 4.2 . 112