UDP is a simple, unreliable datagram protocol
that is 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; the
connect(SSC)
call may also be used to fix the destination for future
packets (in which case the
recv(SSC),
or
read(S)
and
send(SSC),
or
write(S)
system/library calls may be used). In addition,
UDP is available as TLI connectionless
transport via the special file /dev/inet/udp.
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
ip(ADMP).
The UDP driver may also be accessed by opening it
directly. Network related statistics can be obtained by
issuing the following ioctls, defined in
<netinet/ip_var.h> and
<netinet/udp_var.h>, to the driver:
SIOCSMGMT
to set the inpcb associated with the end-point as
a management inpcb (to distinguish it from
others, when network statistics are gathered) and link it
in the list of management inpcbs.
SIOCGUDPSTATS
to extract UDP statistics. The structure
udpstat is passed as an argument to the
I_STR ioctl call.
STIOCGUDB
to fetch the entire UDP table. It is a
transparent ioctl and functions similar to
STIOCBTCB, see
tcp(ADMP).
Diagnostics
A socket operation may fail with one of the following errors returned:
[EISCONN]
when trying to establish a connection on a socket which
already has one, or when trying to send a datagram with the destination
address specified and the socket is already connected
[ENOTCONN]
when trying to send a datagram, but no destination address
is specified, and the socket hasn't been
connected
[ENOSR]
when the system runs out of memory for an internal data structure
[EADDRINUSE]
when an attempt is made to create a socket with a port which has
already been allocated
[EADDRNOTAVAIL]
when an attempt is made to create a socket with a network address
for which no network interface exists.
An ioctl operation may fail with the
errno set to one of the following:
[EINVAL]
when no argument/NULL argument is passed to the
driver, or when the command in the copyresp
structure is not valid, or when the ioc_count is
not TRANSPARENT for a transparent ioctl
[ENXIO]
when the associated file descriptor is no longer open/valid.