1*47675Scael.\" Copyright (c) 1983, 1991 The Regents of the University of California. 236752Sbostic.\" All rights reserved. 320746Smckusick.\" 443581Strent.\" %sccs.include.redist.man% 520746Smckusick.\" 6*47675Scael.\" @(#)udp.4 6.5 (Berkeley) 03/28/91 736752Sbostic.\" 8*47675Scael.Dd 9*47675Scael.Dt UDP 4 10*47675Scael.Os BSD 4.2 11*47675Scael.Sh NAME 12*47675Scael.Nm udp 13*47675Scael.Nd Internet User Datagram Protocol 14*47675Scael.Sh SYNOPSIS 15*47675Scael.Fd #include <sys/socket.h> 16*47675Scael.Fd #include <netinet/in.h> 17*47675Scael.Ft int 18*47675Scael.Fn socket AF_INET SOCK_DGRAM 0 19*47675Scael.Sh DESCRIPTION 20*47675Scael.Tn UDP 21*47675Scaelis a simple, unreliable datagram protocol which is used 22*47675Scaelto support the 23*47675Scael.Dv SOCK_DGRAM 24*47675Scaelabstraction for the Internet 25*47675Scaelprotocol family. 26*47675Scael.Tn UDP 27*47675Scaelsockets are connectionless, and are 2820746Smckusicknormally used with the 29*47675Scael.Xr sendto 3020746Smckusickand 31*47675Scael.Xr recvfrom 3220746Smckusickcalls, though the 33*47675Scael.Xr connect 2 3420746Smckusickcall may also be used to fix the destination for future 3520746Smckusickpackets (in which case the 36*47675Scael.Xr recv 2 3720746Smckusickor 38*47675Scael.Xr read 2 3920746Smckusickand 40*47675Scael.Xr send 2 4120746Smckusickor 42*47675Scael.Xr write 2 4320746Smckusicksystem calls may be used). 44*47675Scael.Pp 45*47675Scael.Tn UDP 46*47675Scaeladdress formats are identical to those used by 47*47675Scael.Tn TCP . 48*47675ScaelIn particular 49*47675Scael.Tn UDP 50*47675Scaelprovides a port identifier in addition 51*47675Scaelto the normal Internet address format. Note that the 52*47675Scael.Tn UDP 53*47675Scaelport 54*47675Scaelspace is separate from the 55*47675Scael.Tn TCP 56*47675Scaelport space (i.e. a 57*47675Scael.Tn UDP 58*47675Scaelport 59*47675Scaelmay not be 60*47675Scael.Dq connected 61*47675Scaelto a 62*47675Scael.Tn TCP 63*47675Scaelport). In addition broadcast 6420746Smckusickpackets may be sent (assuming the underlying network supports 65*47675Scaelthis) by using a reserved 66*47675Scael.Dq broadcast address ; 67*47675Scaelthis address 6820746Smckusickis network interface dependent. 69*47675Scael.Pp 70*47675ScaelOptions at the 71*47675Scael.Tn IP 72*47675Scaeltransport level may be used with 73*47675Scael.Tn UDP ; 74*47675Scaelsee 75*47675Scael.Xr ip 4 . 76*47675Scael.Sh DIAGNOSTICS 7720746SmckusickA socket operation may fail with one of the following errors returned: 78*47675Scael.Bl -tag -width [EADDRNOTAVAIL] 79*47675Scael.It Bq Er EISCONN 8020746Smckusickwhen trying to establish a connection on a socket which 8120746Smckusickalready has one, or when trying to send a datagram with the destination 8220746Smckusickaddress specified and the socket is already connected; 83*47675Scael.It Bq Er ENOTCONN 8420746Smckusickwhen trying to send a datagram, but 8520746Smckusickno destination address is specified, and the socket hasn't been 8620746Smckusickconnected; 87*47675Scael.It Bq Er ENOBUFS 8820746Smckusickwhen the system runs out of memory for 8920746Smckusickan internal data structure; 90*47675Scael.It Bq Er EADDRINUSE 9120746Smckusickwhen an attempt 9220746Smckusickis made to create a socket with a port which has already been 9320746Smckusickallocated; 94*47675Scael.It Bq Er EADDRNOTAVAIL 9520746Smckusickwhen an attempt is made to create a 9620746Smckusicksocket with a network address for which no network interface 9720746Smckusickexists. 98*47675Scael.El 99*47675Scael.Sh SEE ALSO 100*47675Scael.Xr getsockopt 2 , 101*47675Scael.Xr recv 2 , 102*47675Scael.Xr send 2 , 103*47675Scael.Xr socket 2 , 104*47675Scael.Xr intro 4 , 105*47675Scael.Xr inet 4 , 106*47675Scael.Xr ip 4 107*47675Scael.Sh HISTORY 108*47675ScaelThe 109*47675Scael.Nm 110*47675Scaelprotocol appeared in 111*47675Scael.Bx 4.2 . 112