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, although 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.
You can use options at the IP transport level with UDP (see the IP protocol).
A descriptor referencing the socket, or -1 if an error occurs (errno is set).
connect(), getsockopt(), read(), recv(), recvfrom(), send(), sendto(), socket(), write()
Based on RFC 768