udp(4p)udp(4p)Nameudp - Internet User Datagram Protocol
Syntax
#include <sys/socket.h>
#include <netinet/in.h>
s = socket(AF_INET, SOCK_DGRAM, 0);
Description
UDP is a simple, unreliable datagram protocol that is used to support
the SOCK_DGRAM abstraction for the Internet protocol family. UDP sock‐
ets are connectionless and are normally used with the and calls, though
the call can also be used to fix the destination for future packets (in
which case the or and or system calls may be used).
UDP address formats are identical to those used by TCP. In particular,
UDP provides a port identifier in addition to the normal Internet
address format. Note that the UDP port space is separate from the TCP
port space (for example, a UDP port may not be ``connected'' to a TCP
port). In addition broadcast packets can be sent (assuming the under‐
lying network supports this) by using a reserved ``broadcast address'';
this address is network interface dependent. The SO_BROADCAST option
must be set on the socket for broadcasting to succeed.
Diagnostics
A socket operation may fail with one of the following errors returned:
[EISCONN] Try to establish a connection on a socket which already
has one, or when trying to send a datagram with the des‐
tination address specified and the socket already con‐
nected.
[ENOTCONN] Try to send a datagram, but no destination address is
specified, and the socket has not been connected.
[ENOBUFS] The system runs out of memory for an internal data
structure.
[EADDRINUSE] An attempt is made to create a socket with a port that
has already been allocated.
[EADDRNOTAVAIL]
An attempt is made to create a socket with a network
address for which no network interface exists.
See Alsogetsockopt(2), send(2), socket(2)recv(2), intro(4n), inet(4f)udp(4p)