|UDP(7)||Linux Programmer's Manual||UDP(7)|
NAMEudp - User Datagram Protocol for IPv4
DESCRIPTIONThis is an implementation of the User Datagram Protocol described in RFC 768. 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.
Address formatUDP uses the IPv4 sockaddr_in address format described in ip(7).
Error handlingAll fatal errors will be passed to the user as an error return even when the socket is not connected. This includes asynchronous errors received from the network. You may get an error for an earlier packet that was sent on the same socket. This behavior differs from many other BSD socket implementations which don't pass any errors unless the socket is connected. Linux's behavior is mandated by RFC 1122.
/proc interfacesSystem-wide UDP parameter settings can be accessed by files in the directory /proc/sys/net/ipv4/.
- udp_mem (since Linux 2.6.25)
- This is a vector of three integers governing the number of pages allowed for queueing by all UDP sockets.
- Below this number of pages, UDP is not bothered about its memory appetite. When the amount of memory allocated by UDP exceeds this number, UDP starts to moderate memory usage.
- This value was introduced to follow the format of tcp_mem (see tcp(7)).
- Number of pages allowed for queueing by all UDP sockets.
- Defaults values for these three items are calculated at boot time from the amount of available memory.
- udp_rmem_min (integer; default value: PAGE_SIZE; since Linux 2.6.25)
- Minimal size, in bytes, of receive buffers used by UDP sockets in moderation. Each UDP socket is able to use the size for receiving data, even if total pages of UDP sockets exceed udp_mem pressure.
- udp_wmem_min (integer; default value: PAGE_SIZE; since Linux 2.6.25)
- Minimal size, in bytes, of send buffer used by UDP sockets in moderation. Each UDP socket is able to use the size for sending data, even if total pages of UDP sockets exceed udp_mem pressure.
Socket optionsTo set or get a UDP socket option, call getsockopt(2) to read or setsockopt(2) to write the option with the option level argument set to IPPROTO_UDP. Unless otherwise noted, optval is a pointer to an int.
- UDP_CORK (since Linux 2.5.44)
- If this option is enabled, then all data output on this socket is accumulated into a single datagram that is transmitted when the option is disabled. This option should not be used in code intended to be portable.
IoctlsThese ioctls can be accessed using ioctl(2). The correct syntax is:
int value ;
error = ioctl( udp_socket , ioctl_type , & value );
- FIONREAD ( SIOCINQ)
- Gets a pointer to an integer as argument. Returns the size of the next pending datagram in the integer in bytes, or 0 when no datagram is pending. Warning: Using FIONREAD, it is impossible to distinguish the case where no datagram is pending from the case where the next pending datagram contains zero bytes of data. It is safer to use select(2), poll(2), or epoll(7) to distinguish these cases.
- TIOCOUTQ ( SIOCOUTQ)
- Returns the number of data bytes in the local send queue. Only supported with Linux 2.4 and above.
In addition all ioctls documented in ip(7) and socket(7) are supported.
ERRORSAll errors documented for socket(7) or ip(7) may be returned by a send or receive on a UDP socket.
- No receiver was associated with the destination address. This might be caused by a previous packet sent over the socket.
VERSIONSIP_RECVERR is a new feature in Linux 2.2.
SEE ALSOip(7), raw(7), socket(7), udplite(7)
COLOPHONThis page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/.