]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man7/udp.7
Import of man-pages 1.70
[thirdparty/man-pages.git] / man7 / udp.7
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.7 2000/01/22 01:55:05 freitag Exp $
7 .TH UDP 7 1998-10-02 "Linux Man Page" "Linux Programmer's Manual"
8 .SH NAME
9 udp \- User Datagram Protocol for IPv4
10 .SH SYNOPSIS
11 .B #include <sys/socket.h>
12 .br
13 .B #include <netinet/in.h>
14 .br
15 .B udp_socket = socket(PF_INET, SOCK_DGRAM, 0);
16 .SH DESCRIPTION
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.
21
22 When a UDP socket is created, its local and remote addresses are unspecified.
23 Datagrams can be sent immediately using
24 .BR sendto (2)
25 or
26 .BR sendmsg (2)
27 with a valid destination address as an argument. When
28 .BR connect (2)
29 is called on the socket the default destination address is set and datagrams
30 can now be sent using
31 .BR send (2)
32 or
33 .BR write (2)
34 without specifying an destination address.
35 It is still possible to send to other destinations by passing an address to
36 .BR sendto (2)
37 or
38 .BR sendmsg (2).
39 In order to receive packets the socket can be bound to an local
40 address first by using
41 .BR bind (2).
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
46 .IR INADDR_ANY .
47
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
51 .B MSG_TRUNC
52 flag is set.
53 .I MSG_WAITALL
54 is not supported.
55
56 IP options may be sent or received using the socket options described in
57 .BR ip (7).
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
60 .BR ip (7).
61
62 When the
63 .B MSG_DONTROUTE
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.
66
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
70 as described in the
71 .B IP_MTU_DISCOVER
72 section of
73 .BR ip (7).
74
75 .SH "ADDRESS FORMAT"
76 UDP uses the IPv4
77 .B sockaddr_in
78 address format described in
79 .BR ip (7).
80
81 .SH "ERROR HANDLING"
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
89 .BR RFC1122 .
90
91 For compatibility with legacy code it is possible to set the
92 .B SO_BSDCOMPAT
93 SOL_SOCKET option to receive remote errors only when the socket has been
94 connected (except for
95 .B EPROTO
96 and
97 .BR EMSGSIZE ).
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.
101
102 When the
103 .B IP_RECVERR
104 option is enabled all errors are stored in the socket error queue
105 and can be received by
106 .BR recvmsg (2)
107 with the
108 .B MSG_ERRQUEUE
109 flag set.
110 .SH IOCTLS
111 These ioctls can be accessed using
112 .BR ioctl (2).
113 The correct syntax is:
114 .PP
115 .RS
116 .nf
117 .BI int " value";
118 .IB error " = ioctl(" tcp_socket ", " ioctl_type ", &" value ");"
119 .fi
120 .RE
121 .TP
122 .BR FIONREAD " (" SIOCINQ )
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.
125 .TP
126 .BR TIOCOUTQ " (" SIOCOUTQ )
127 Returns the number of data bytes in the local send queue. Only supported
128 with Linux 2.4 and above.
129 .PP
130 In addition all ioctls documented in
131 .BR ip (7)
132 and
133 .BR socket (7)
134 are supported.
135 .SH ERRORS
136 All errors documented for
137 .BR socket (7)
138 or
139 .BR ip (7)
140 may be returned by a send or receive on a UDP socket.
141
142 .B ECONNREFUSED
143 No receiver was associated with the destination address. This might be
144 caused by a previous packet sent over the socket.
145
146 .SH VERSIONS
147 IP_RECVERR is a new feature in Linux 2.2.
148
149 .SH CREDITS
150 This man page was written by Andi Kleen.
151
152 .SH "SEE ALSO"
153 .BR ip (7),
154 .BR raw (7),
155 .BR socket (7)
156
157 RFC768 for the User Datagram Protocol.
158 .br
159 RFC1122 for the host requirements.
160 .br
161 RFC1191 for a description of path MTU discovery.