Seth Woolley's Man Viewer

udp(7) - udp, udp - User Datagram Protocol for IPv4 - man 7 udp

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

UDP(7)                     Linux Programmer's Manual                    UDP(7)



NAME
       udp - User Datagram Protocol for IPv4

SYNOPSIS
       #include <sys/socket.h>
       #include <netinet/in.h>
       udp_socket = socket(2,7,n)(PF_INET, SOCK_DGRAM, 0);

DESCRIPTION
       This  is  an  implemention  of  the User Datagram Protocol described in(1,8)
       RFC768. It implements a connectionless, unreliable datagram packet ser-
       vice.   Packets  may be reordered or duplicated before they arrive. UDP
       generates and checks checksums to catch transmission errors.

       When a UDP socket(2,7,n) is  created,  its  local  and  remote  addresses  are
       unspecified.   Datagrams  can  be  sent  immediately using sendto(2) or
       sendmsg(2) with a valid destination address as an argument.  When  con-
       nect(2)  is called on the socket(2,7,n) the default destination address is set(7,n,1 builtins)
       and datagrams can now be sent using send(2,n)(2) or write(1,2)(2) without  speci-
       fying  an  destination  address.  It is still possible to send(2,n) to other
       destinations by passing an address  to  sendto(2)  or  sendmsg(2).   In
       order  to  receive  packets the socket(2,7,n) can be bound to an local address
       first by using bind(2,n,1 builtins)(2).  Otherwise the socket(2,7,n) layer will  automatically
       assign   a   free   local   port   out   of   the   range   defined  by
       net.ipv4.ip_local_port_range and bind(2,n,1 builtins) the socket(2,7,n) to INADDR_ANY.

       All receive operations return only 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.
       MSG_WAITALL is not supported.

       IP  options  may be sent or received using the socket(2,7,n) options described
       in(1,8) ip(7,8)(7).  They are only processed by the kernel when  the  appropriate
       sysctl(2,5,8)  is enabled (but still passed to the user even when it is turned
       off). See ip(7,8)(7).

       When the MSG_DONTROUTE flag is set(7,n,1 builtins) on sending the  destination  address
       must refer to an local interface address and the packet is only sent to
       that interface.

       UDP fragments a packet when its total length exceeds the interface  MTU
       (Maximum Transmission Unit).  A more network friendly alternative is to
       use path MTU discovery as described in(1,8) the IP_MTU_DISCOVER  section  of
       ip(7,8)(7).


ADDRESS FORMAT
       UDP uses the IPv4 sockaddr_in address format described in(1,8) ip(7,8)(7).


ERROR HANDLING
       All  fatal  errors  will  be passed to the user as an error(8,n) return even
       when the socket(2,7,n) is not connected.  This  includes  asynchronous  errors
       received  from  the network. You may get an error(8,n) for an earlier packet
       that was sent on the same socket.  This  behaviour  differs  from  many
       other BSD socket(2,7,n) implementations which don't pass any errors unless the
       socket(2,7,n) is connected.  Linux's behaviour is mandated by RFC1122.

       For compatibility with legacy code it is possible to set(7,n,1 builtins) the SO_BSDCOM-
       PAT SOL_SOCKET option to receive remote errors only when the socket(2,7,n) has
       been connected (except for EPROTO and EMSGSIZE).  It is better  to  fix
       the code to handle errors properly than to enable this option.  Locally
       generated errors are always passed.

       When the IP_RECVERR option is enabled all  errors  are  stored  in(1,8)  the
       socket(2,7,n)  error(8,n)  queue(1,3)  and  can  be  received  by  recvmsg(2)  with  the
       MSG_ERRQUEUE flag set.

IOCTLS
       These ioctls can be accessed using ioctl(2).  The correct syntax is:

              int value;
              error(8,n) = ioctl(tcp_socket, ioctl_type, &value);

       FIONREAD (SIOCINQ)
              Gets a pointer to an integer as argument. Returns  the  size  of
              the  next pending datagram in(1,8) the integer in(1,8) bytes, or 0 when no
              datagram is pending.

       TIOCOUTQ (SIOCOUTQ)
              Returns the number of data bytes in(1,8) the local send(2,n)  queue.  Only
              supported with Linux 2.4 and above.

       In addition all ioctls documented in(1,8) ip(7,8)(7) and socket(2,7,n)(7) are supported.

ERRORS
       All errors documented for socket(2,7,n)(7) or ip(7,8)(7) may be returned by a  send(2,n)
       or receive on a UDP socket.

       ECONNREFUSED  No  receiver was associated with the destination address.
       This might be caused by a previous packet sent over the socket.


VERSIONS
       IP_RECVERR is a new feature in(1,8) Linux 2.2.


CREDITS
       This man(1,5,7) page was written by Andi Kleen.


SEE ALSO
       ip(7,8)(7), raw(3x,7,8,3x cbreak)(7), socket(2,7,n)(7)

       RFC768 for the User Datagram Protocol.
       RFC1122 for the host(1,5) requirements.
       RFC1191 for a description of path MTU discovery.



Linux Man Page                    1998-10-02                            UDP(7)

References for this manual (incoming links)