Internet User Datagram Protocol
#include <sys/socket.h> #include <netinet/in.h> int socket( AF_INET, SOCK_DGRAM, 0 );
UDP is a simple, unreliable datagram protocol that's used to support the SOCK_DGRAM abstraction for the Internet protocol family. UDP sockets are connectionless and are normally used with the sendto() and recvfrom() calls, though you can also use the connect() call to fix the destination for future packets (in which case you can use the recv() or read() and send() or write() system calls).
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; that is, a UDP port may not be ``connected'' to a TCP port. In addition, broadcast packets may be sent - assuming the underlying network supports this - by using a reserved broadcast address; this address is network-interface dependent.
Options at the IP transport level may be used with UDP (see the IP protocol).
A descriptor referencing the socket, or -1 if an error occurred (errno is set).
If an error occurred, errno could contain one of the following:
IP protocol, getsockopt(), recv(), send(), socket()
RFC 768