UDP

Internet User Datagram Protocol

Synopsis:

#include <sys/socket.h>
#include <netinet/in.h>

int socket( AF_INET, 
            SOCK_DGRAM, 
            0 );

Description:

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).

Returns:

A descriptor referencing the socket, or -1 if an error occurred (errno is set).

Errors:

If an error occurred, errno could contain one of the following:

EADDRINUSE
Tried to create a socket with a port that has already been allocated.
EADDRNOTAVAIL
Tried to create a socket with a network address for which no network interface exists.
EISCONN
Tried to establish a connection on a socket that already has one, or to send a datagram with the destination address specified and the socket is already connected.
ENOBUFS
The system ran out of memory for an internal data structure.
ENOTCONN
Tried to send a datagram, but no destination address was specified and the socket hasn't been connected.

See also:

IP protocol, getsockopt(), recv(), send(), socket()

RFC 768