other versions
- wheezy 3.44-1
- jessie 3.74-1
- jessie-backports 4.10-2~bpo8+1
- testing 4.10-2
- unstable 4.10-2
other languages
other sections
UDP(7) | Linux Programmer's Manual | UDP(7) |
NAME¶
udp - User Datagram Protocol for IPv4SYNOPSIS¶
#include <sys/socket.h>DESCRIPTION¶
This 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 Format¶
UDP uses the IPv4 sockaddr_in address format described in ip(7).Error Handling¶
All 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 interfaces¶
System-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.
- min
- 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.
- pressure
- This value was introduced to follow the format of tcp_mem (see tcp(7)).
- max
- 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 Options¶
To 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.- 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.
Ioctls¶
These 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.
ERRORS¶
All errors documented for socket(7) or ip(7) may be returned by a send 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 Linux 2.2.SEE ALSO¶
ip(7), raw(7), socket(7), udplite(7)COLOPHON¶
This page is part of release 3.44 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/.2010-06-13 | Linux |