This is an implemention of the User Data Protocol described in RFC768. It
implements a connectionless, unreliable datagram packet service.
Packets may be reordered or duplicated before they arrive. UDP
generates and checks checksums to catch transmission errors.
When a UDP socket is created its local and remote address is unspecified.
Datagrams can be sent immediately using
sendto (2)
or
sendmsg (2)
with a valid destination address as an argument. When
connect (2)
is called on the socket the default foreign address is set and datagrams
can be sent now using
send (2)
or
write (2)
without specifying an destination address.
It is still possible to send to other destinations by passing an address to
sendto (2)
or
sendmsg (2).
In order to receive packets the socket should be bound to an local
address first by using
bind(2)
, when this is not the case the sockets layer will automatically assign
a local port on the first user receive request.
All receive operations only return one packet. When the packet is smaller
than the passed buffer only that much data is returned, when it is bigger
the packet is truncated and the
MSG_TRUNC
flag is set.
IP options may be sent or received using the socket options described in
ip (4).
They are only processed by the kernel when the appropriate sysctl
is enabled (but still passed to the user even when it is turned off). See
ip (4).
When the
MSG_DONTROUTE
flag is set on sending the destination address must refer to an local
interface address and the packet is only sent to that interface.