1 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
2 .\" Permission is granted to distribute possibly modified copies
3 .\" of this page provided the header is included verbatim,
4 .\" and in case of nontrivial modification author and date
5 .\" of the modification is added to the header.
6 .\" $Id: udp.7,v 1.1 2003/12/20 03:31:54 bbbush Exp $
7 .TH UDP 7 1998-10-02 "Linux Man Page" "Linux Programmer's Manual"
9 udp \- User Datagram Protocol for IPv4
11 .B #include <sys/socket.h>
13 .B #include <netinet/in.h>
15 .B udp_socket = socket(PF_INET, SOCK_DGRAM, 0);
17 This is an implemention of the User Datagram Protocol described in RFC768. It
18 implements a connectionless, unreliable datagram packet service.
19 Packets may be reordered or duplicated before they arrive. UDP
20 generates and checks checksums to catch transmission errors.
22 When a UDP socket is created, its local and remote addresses are unspecified.
23 Datagrams can be sent immediately using
27 with a valid destination address as an argument. When
29 is called on the socket the default destination address is set and datagrams
34 without specifying an destination address.
35 It is still possible to send to other destinations by passing an address to
39 In order to receive packets the socket can be bound to an local
40 address first by using
42 Otherwise the socket layer will automatically assign
43 a free local port out of the range defined by
44 .I net.ipv4.ip_local_port_range
45 and bind the socket to
48 All receive operations return only one packet. When the packet is smaller
49 than the passed buffer only that much data is returned, when it is bigger
50 the packet is truncated and the
56 IP options may be sent or received using the socket options described in
58 They are only processed by the kernel when the appropriate sysctl
59 is enabled (but still passed to the user even when it is turned off). See
64 flag is set on sending the destination address must refer to an local
65 interface address and the packet is only sent to that interface.
67 UDP fragments a packet when its total length exceeds the interface MTU
68 (Maximum Transmission Unit).
69 A more network friendly alternative is to use path MTU discovery
78 address format described in
82 All fatal errors will be passed to the user as an error return even
83 when the socket is not connected. This includes asynchronous errors
84 received from the network. You may get an error for an earlier packet
85 that was sent on the same socket.
86 This behaviour differs from many other BSD socket implementations
87 which don't pass any errors unless the socket is connected.
88 Linux's behaviour is mandated by
91 For compatibility with legacy code it is possible to set the
93 SOL_SOCKET option to receive remote errors only when the socket has been
98 It is better to fix the
99 code to handle errors properly than to enable this option.
100 Locally generated errors are always passed.
104 option is enabled all errors are stored in the socket error queue
105 and can be received by
111 These ioctls can be accessed using
113 The correct syntax is:
118 .IB error " = ioctl(" tcp_socket ", " ioctl_type ", &" value ");"
123 Gets a pointer to an integer as argument. Returns the size of the next
124 pending datagram in the integer in bytes, or 0 when no datagram is pending.
127 Returns the number of data bytes in the local send queue. Only supported
128 with Linux 2.4 and above.
130 In addition all ioctls documented in
136 All errors documented for
140 may be returned by a send or receive on a UDP socket.
143 No receiver was associated with the destination address. This might be
144 caused by a previous packet sent over the socket.
147 IP_RECVERR is a new feature in Linux 2.2.
150 This man page was written by Andi Kleen.
157 RFC768 for the User Datagram Protocol.
159 RFC1122 for the host requirements.
161 RFC1191 for a description of path MTU discovery.