udp(7tcp)


udp -- Internet User Datagram Protocol

Synopsis

Programmer's interface:
#include <sys/types.h>
#include  <sys/socket.h>
#include  <netinet/in.h>

s = socket(AF_INET, SOCK_DGRAM, 0); s = socket(AF_INET6, SOCK_DGRAM, 0);

#include <paths.h> #include <fcntl.h> #include <netinet/ip_var.h> #include <netinet/udp.h> #include <netinet/udp_var.h>

fd = open(_PATH_UDP, flags); fd = open(_PATH_UDPIPV6, flags);

Description

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(3sock) call may also be used to fix the destination for future packets (in which case the recv(3sock), or read(2) and send(3sock), or write(2) 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 IPv4 transport level may be used with UDP if AF_INET is specified; see ip(7tcp). Options at the IPv6 transport level may be used with UDP if AF_INET6 is specified; see ipv6(7tcp).

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

Diagnostics

A socket operation may fail with one of the following errors returned:

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

[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

[ENOMEM]
when the system runs out of memory for an internal data structure

[ENOSR]
when the system runs out of STREAMS

[ENOTCONN]
when trying to send a datagram, but no destination address is specified, and the socket has not been connected

[ENXIO]
when no more UDP devices are available
An ioctl operation may fail with the errno set to one of the following:

[EINVAL]
when an invalid 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.

References

getsockopt(3sock), if(7tcp), inconfig(1Mtcp), inet(7tcp), ip(7tcp), recv(3sock), send(3sock), socket(3sock), streamio(7), tcp(7tcp)

``User Datagram Protocol (UDP) parameters'' on the inconfig(1Mtcp) manual page

RFC 768, RFC 1122


© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004