{
    "mode": "man",
    "parameter": "udp",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/udp/7/json",
    "generated": "2026-06-02T23:35:18Z",
    "synopsis": "",
    "sections": {
        "NAME": {
            "content": "udp - User Datagram Protocol for IPv4\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "",
            "subsections": [
                {
                    "name": "#include <sys/socket.h>",
                    "content": ""
                },
                {
                    "name": "#include <netinet/in.h>",
                    "content": ""
                },
                {
                    "name": "#include <netinet/udp.h>",
                    "content": "udpsocket = socket(AFINET, SOCKDGRAM, 0);\n"
                }
            ]
        },
        "DESCRIPTION": {
            "content": "This  is an implementation of the User Datagram Protocol described in RFC 768.  It implements\na connectionless, unreliable datagram packet service.  Packets may be reordered or duplicated\nbefore they arrive.  UDP generates and checks checksums to catch transmission errors.\n\nWhen  a UDP socket is created, its local and remote addresses are unspecified.  Datagrams can\nbe sent immediately using sendto(2) or sendmsg(2) with a valid destination address as an  ar‐\ngument.   When connect(2) is called on the socket, the default destination address is set and\ndatagrams can now be sent using send(2) or write(2) without specifying a destination address.\nIt  is  still  possible  to  send to other destinations by passing an address to sendto(2) or\nsendmsg(2).  In order to receive packets, the socket can be bound to a local address first by\nusing  bind(2).   Otherwise, the socket layer will automatically assign a free local port out\nof the range defined by /proc/sys/net/ipv4/iplocalportrange and bind  the  socket  to  IN‐‐\nADDRANY.\n\nAll  receive  operations  return only one packet.  When the packet is smaller than the passed\nbuffer, only that much data is returned; when it is bigger, the packet is truncated  and  the\nMSGTRUNC flag is set.  MSGWAITALL is not supported.\n\nIP  options  may  be  sent or received using the socket options described in ip(7).  They are\nprocessed by the kernel only when the appropriate  /proc  parameter  is  enabled  (but  still\npassed to the user even when it is turned off).  See ip(7).\n\nWhen  the MSGDONTROUTE flag is set on sending, the destination address must refer to a local\ninterface address and the packet is sent only to that interface.\n\nBy default, Linux UDP does path MTU (Maximum Transmission Unit) discovery.   This  means  the\nkernel  will keep track of the MTU to a specific target IP address and return EMSGSIZE when a\nUDP packet write exceeds it.  When this happens, the application should decrease  the  packet\nsize.   Path  MTU discovery can be also turned off using the IPMTUDISCOVER socket option or\nthe /proc/sys/net/ipv4/ipnopmtudisc file; see ip(7) for details.   When  turned  off,  UDP\nwill  fragment  outgoing UDP packets that exceed the interface MTU.  However, disabling it is\nnot recommended for performance and reliability reasons.\n",
            "subsections": [
                {
                    "name": "Address format",
                    "content": "UDP uses the IPv4 sockaddrin address format described in ip(7).\n"
                },
                {
                    "name": "Error handling",
                    "content": "All fatal errors will be passed to the user as an error return even when the  socket  is  not\nconnected.   This includes asynchronous errors received from the network.  You may get an er‐\nror for an earlier packet that was sent on the same socket.  This behavior differs from  many\nother  BSD socket implementations which don't pass any errors unless the socket is connected.\nLinux's behavior is mandated by RFC 1122.\n\nFor compatibility with legacy code, in Linux 2.0 and 2.2 it was possible to set  the  SOBSD‐‐\nCOMPAT  SOLSOCKET  option  to  receive remote errors only when the socket has been connected\n(except for EPROTO and EMSGSIZE).  Locally generated errors are always passed.   Support  for\nthis socket option was removed in later kernels; see socket(7) for further information.\n\nWhen  the  IPRECVERR option is enabled, all errors are stored in the socket error queue, and\ncan be received by recvmsg(2) with the MSGERRQUEUE flag set.\n"
                },
                {
                    "name": "/proc interfaces",
                    "content": "System-wide  UDP  parameter  settings  can  be   accessed   by   files   in   the   directory\n/proc/sys/net/ipv4/.\n\nudpmem (since Linux 2.6.25)\nThis  is a vector of three integers governing the number of pages allowed for queueing\nby all UDP sockets.\n\nmin    Below this number of pages, UDP is not  bothered  about  its  memory  appetite.\nWhen  the  amount of memory allocated by UDP exceeds this number, UDP starts to\nmoderate memory usage.\n\npressure\nThis value was introduced to follow the format of tcpmem (see tcp(7)).\n\nmax    Number of pages allowed for queueing by all UDP sockets.\n\nDefaults values for these three items are calculated at boot time from the  amount  of\navailable memory.\n\nudprmemmin (integer; default value: PAGESIZE; since Linux 2.6.25)\nMinimal  size,  in  bytes, of receive buffers used by UDP sockets in moderation.  Each\nUDP socket is able to use the size for receiving data, even  if  total  pages  of  UDP\nsockets exceed udpmem pressure.\n\nudpwmemmin (integer; default value: PAGESIZE; since Linux 2.6.25)\nMinimal  size,  in  bytes, of send buffer used by UDP sockets in moderation.  Each UDP\nsocket is able to use the size for sending data, even if total pages  of  UDP  sockets\nexceed udpmem pressure.\n"
                },
                {
                    "name": "Socket options",
                    "content": "To  set  or get a UDP socket option, call getsockopt(2) to read or setsockopt(2) to write the\noption with the option level argument set to IPPROTOUDP.  Unless otherwise noted, optval  is\na pointer to an int.\n\nFollowing is a list of UDP-specific socket options.  For details of some other socket options\nthat are also applicable for UDP sockets, see socket(7).\n\nUDPCORK (since Linux 2.5.44)\nIf this option is enabled, then all data output on this socket is accumulated  into  a\nsingle  datagram  that is transmitted when the option is disabled.  This option should\nnot be used in code intended to be portable.\n"
                },
                {
                    "name": "Ioctls",
                    "content": "These ioctls can be accessed using ioctl(2).  The correct syntax is:\n\nint value;\nerror = ioctl(udpsocket, ioctltype, &value);\n\nFIONREAD (SIOCINQ)\nGets a pointer to an integer as argument.  Returns the size of the next pending  data‐\ngram  in the integer in bytes, or 0 when no datagram is pending.  Warning: Using FION‐‐\nREAD, it is impossible to distinguish the case where no datagram is pending  from  the\ncase  where the next pending datagram contains zero bytes of data.  It is safer to use\nselect(2), poll(2), or epoll(7) to distinguish these cases.\n\nTIOCOUTQ (SIOCOUTQ)\nReturns the number of data bytes in the local send queue.  Supported only  with  Linux\n2.4 and above.\n\nIn addition, all ioctls documented in ip(7) and socket(7) are supported.\n"
                }
            ]
        },
        "ERRORS": {
            "content": "All  errors  documented  for socket(7) or ip(7) may be returned by a send or receive on a UDP\nsocket.\n\nECONNREFUSED\nNo receiver was associated with the destination address.  This might be  caused  by  a\nprevious packet sent over the socket.\n",
            "subsections": []
        },
        "VERSIONS": {
            "content": "IPRECVERR is a new feature in Linux 2.2.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "ip(7), raw(7), socket(7), udplite(7)\n\nThe kernel source file Documentation/networking/ip-sysctl.txt.\n\nRFC 768 for the User Datagram Protocol.\nRFC 1122 for the host requirements.\nRFC 1191 for a description of path MTU discovery.\n",
            "subsections": []
        },
        "COLOPHON": {
            "content": "This  page  is  part  of  release  5.10 of the Linux man-pages project.  A description of the\nproject, information about reporting bugs, and the latest version of this page, can be  found\nat https://www.kernel.org/doc/man-pages/.\n\n\n\nLinux                                        2020-04-11                                       UDP(7)",
            "subsections": []
        }
    },
    "summary": "udp - User Datagram Protocol for IPv4",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "ip",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/ip/7/json"
        },
        {
            "name": "raw",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/raw/7/json"
        },
        {
            "name": "socket",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/socket/7/json"
        },
        {
            "name": "udplite",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/udplite/7/json"
        }
    ]
}