1udp(7P)                            Protocols                           udp(7P)
2
3
4

NAME

6       udp, UDP - Internet User Datagram Protocol
7

SYNOPSIS

9       #include <sys/socket.h>
10
11
12       #include <netinet/in.h>
13
14
15       s = socket(AF_INET, SOCK_DGRAM, 0);
16
17
18       s = socket(AF_INET6, SOCK_DGRAM, 0);
19
20
21       t = t_open("/dev/udp", O_RDWR);
22
23
24       t = t_open("/dev/udp6", O_RDWR);
25
26

DESCRIPTION

28       UDP  is  a simple datagram protocol which is layered directly above the
29       Internet Protocol ("IP") or the Internet Protocol Version  6  ("IPv6").
30       Programs  may access  UDP using the socket interface, where it supports
31       the SOCK_DGRAM socket type, or  using  the  Transport  Level  Interface
32       ("TLI"), where it supports the connectionless (T_CLTS) service type.
33
34
35       Within  the  socket  interface, UDP is normally used with the sendto(),
36       sendmsg(), recvfrom(),  and  recvmsg()  calls  (see  send(3SOCKET)  and
37       recv(3SOCKET)).  If the connect(3SOCKET) call is used to fix the desti‐
38       nation for future  packets,  then  the  recv(3SOCKET)  or  read(2)  and
39       send(3SOCKET) or write(2) calls may be used.
40
41
42       UDP  address  formats  are  identical to those used by the Transmission
43       Control Protocol ("TCP"). Like TCP, UDP uses a port number  along  with
44       an IPor IPv6 address to identify the endpoint of communication. The UDP
45       port number space is separate from the TCP port number space, that  is,
46       a UDP port may not be "connected" to a TCP port. The bind(3SOCKET) call
47       can be used to set the local address and port number of a  UDP  socket.
48       The local IP or IPv6 address may be left unspecified in the bind() call
49       by using the special  value  INADDR_ANY  for  IP,  or  the  unspecified
50       address  (all zeroes) for IPv6. If the bind() call is not done, a local
51       IP or IPv6 address and port number will be assigned  to   the  endpoint
52       when  the first packet is sent. Broadcast packets may be sent, assuming
53       the underlying network supports this, by using  a  reserved  "broadcast
54       address"  This  address  is network interface dependent. Broadcasts may
55       only be sent by the privileged user.
56
57
58       Note that no two UDP sockets can be bound to the same port  unless  the
59       bound  IP addresses are different. IPv4 INADDR_ANY and IPv6 unspecified
60       addresses compare as equal to any IPv4 or IPv6 address. For example, if
61       a  socket  is bound to INADDR_ANY or unspecified address and port X, no
62       other socket can bind to port X, regardless  of  the  binding  address.
63       This special consideration of INADDR_ANY and unspecified address can be
64       changed using the SO_REUSEADDR socket option.  If SO_REUSEADDR  is  set
65       on  a socket doing a bind, IPv4 INADDR_ANY and IPv6 unspecified address
66       do not compare as equal to any IP address. This means that as  long  as
67       the two sockets are not both bound to INADDR_ANY/unspecified address or
68       the same IP address, the two sockets can be bound to the same port.
69
70
71       If an application does not want  to  allow  another  socket  using  the
72       SO_REUSEADDR  option  to  bind  to  a  port its socket is bound to, the
73       application can set the socket level option SO_EXCLBIND  on  a  socket.
74       The  option  values  of  0  and  1 represent enabling and disabling the
75       option, respectively.  Once this option is  enabled  on  a  socket,  no
76       other socket can be bound to the same port.
77
78
79       IPv6  does not support broadcast addresses; their function is supported
80       by IPv6 multicast addresses.
81
82
83       Options at the IP level may be used with UDP. See  ip(7P)  or  ip6(7P).
84       Additionally,  there  is  one UDP-level option of interest to IPsec Key
85       Management applications (see ipsec(7P)and pf_key(7P)):
86
87       UDP_NAT_T_ENDPOINT
88
89           If this boolean option is set, datagrams sent via this socket  will
90           have a non-ESP marker inserted between the UDP header and the data.
91           Likewise, inbound packets that match the endpoint's local-port will
92           be  demultiplexed  between  ESP or the endpoint itself if a non-ESP
93           marker is present. This option is only available  on  IPv4  sockets
94           (AF_INET),  and  the  application must have sufficient privilege to
95           use PF_KEY sockets to also enable this option.
96
97
98
99       There are a variety of ways that a UDP packet can be lost or corrupted,
100       including  a  failure  of  the  underlying communication mechanism. UDP
101       implements a checksum over the data  portion  of  the  packet.  If  the
102       checksum  of  a received packet is in error, the packet will be dropped
103       with no indication given to the user. A queue of  received  packets  is
104       provided for each UDP socket. This queue has a limited capacity. Arriv‐
105       ing datagrams which will not fit within  its  high-water  capacity  are
106       silently discarded.
107
108
109       UDP  processes  Internet Control Message Protocol ("ICMP") and Internet
110       Control Message Protocol Version 6 ("ICMP6") error messages received in
111       response to UDP packets it has sent. See icmp(7P) and icmp6(7P).
112
113
114       ICMP  "source  quench" messages are ignored. ICMP "destination unreach‐
115       able," "time exceeded" and "parameter problem" messages disconnect  the
116       socket  from its peer so that subsequent attempts to send packets using
117       that socket will return an error. UDP will not guarantee  that  packets
118       are  delivered  in the order they were sent. As well, duplicate packets
119       may be generated in the communication process.
120
121
122       ICMP6 "destination unreachable" packets are ignored unless the enclosed
123       code indicates that the port is not in use on the target host, in which
124       case, the application is notified. ICMP6 "parameter problem"  notifica‐
125       tions  are  similarly  passed  upstream.  All  other ICMP6 messages are
126       ignored.
127

SEE ALSO

129       read(2),  write(2),  bind(3SOCKET),  connect(3SOCKET),   recv(3SOCKET),
130       send(3SOCKET),   icmp(7P),   icmp6(7P),  inet(7P),  inet6(7P),  ip(7P),
131       ipsec(7P), ip6(7P), pf_key(7P), tcp(7P)
132
133
134       Postel, Jon, RFC 768, User Datagram Protocol, Network Information  Cen‐
135       ter, SRI International, Menlo Park, Calif., August 1980
136
137
138       Huttunen,  A.,  Swander,  B., Volpe, V., DiBurro, L., Stenberg, M., RFC
139       3948, UDP Encapsulation of IPsec ESP  Packets,  The  Internet  Society,
140       2005.
141

DIAGNOSTICS

143       A socket operation may fail if:
144
145       EISCONN          A  connect()  operation  was  attempted on a socket on
146                        which a connect()  operation  had  already  been  per‐
147                        formed,  and the socket could not be successfully dis‐
148                        connected before making the new connection.
149
150
151       EISCONN          A  sendto()  or  sendmsg()  operation  specifying   an
152                        address  to  which  the  message  should  be  sent was
153                        attempted on a socket on which a  connect()  operation
154                        had already been performed.
155
156
157       ENOTCONN         A  send()  or  write()  operation,  or  a  sendto() or
158                        sendmsg() operation not specifying an address to which
159                        the  message should be sent, was attempted on a socket
160                        on which a connect() operation had  not  already  been
161                        performed.
162
163
164       EADDRINUSE       A  bind()  operation  was attempted on a socket with a
165                        network address/port pair that has already been  bound
166                        to another socket.
167
168
169       EADDRNOTAVAIL    A  bind()  operation  was attempted on a socket with a
170                        network address for which no network interface exists.
171
172
173       EINVAL           A sendmsg() operation with  a  non-NULL  msg_accrights
174                        was attempted.
175
176
177       EACCES           A  bind()  operation  was  attempted with a "reserved"
178                        port number and the effective user ID of  the  process
179                        was not the privileged user.
180
181
182       ENOBUFS          The  system ran out of memory for internal data struc‐
183                        tures.
184
185
186
187
188SunOS 5.11                        4 July 2006                          udp(7P)
Impressum