UDP — Internet User Datagram Protocol
s = socket(AF_INET, SOCK_DGRAM, 0);
s = socket(AF_INET6, SOCK_DGRAM, 0);
is a simple, unreliable datagram protocol used to support the
socket type for the internet protocol family.
sockets are connectionless, and are normally used with the
call can also be used to simulate a connection (see
When used in this manner,
it fixes the destination for future transmitted packets
(in which case the
system calls can be used),
as well as designating the source from which packets are received.
calls can be used at any time if the source of the message is unimportant.
address formats are identical to those used by
requires a port identifier
in addition to the normal Internet address format.
Note that the
port domain is separate from the
port domain (in other words, a
port cannot be connected to a
The default send buffer size for UDP sockets is 65535 bytes.
The default receive buffer size for UDP sockets is 2147483647 bytes.
The send and receive buffer sizes for UDP sockets
can be set by using the
options of the
system call or the
options of the
The maximum size for these buffers
is 2147483647 bytes. The maximum receive buffer size may be
lowered using the
The maximum message size for a UDP datagram
socket is limited by the lesser of the maximum
size of an IP datagram and the size of the UDP
datagram socket buffer.
The maximum size of an IP
datagram limits the maximum message size of a UDP
message to 65507 bytes. Therefore, using the maximum socket
buffer size will allow multiple maximum-sized
messages to be placed on the send queue. The default
inbound and outbound message size limit for a UDP
datagram socket is 65535 bytes.
message size for a UDP broadcast is limited by the
MTU size of the underlying link.
One of the following errors may be returned in
socket operation fails.
For a more detailed list of errors, see the man pages for specific
Attempt to send a datagram
with the destination address specified,
when the socket is already connected.
No buffer space is available for an internal data structure.
Attempt to create a socket with a port which has already been allocated.
Attempt to create a socket with a network address
for which no network interface exists.
The socket interfaces to UDP
were developed by the University of California, Berkeley.