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 $
8 .\" Japanese Version Copyright (c) 1999 NAKANO Takeo all rights reserved.
9 .\" Translated 1999-12-06, NAKANO Takeo <nakano@apm.seikei.ac.jp>
10 .\" Updated 2005-10-09, Kentaro Shirakata <argrath@ub32.org>
11 .\" Updated 2007-01-05, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.43
12 .\" Updated 2008-12-29, Akihiro MOTOKI, LDP v3.14
13 .\" Updated 2010-04-10, Akihiro MOTOKI, LDP v3.24
15 .TH UDP 7 2009-09-30 "Linux" "Linux Programmer's Manual"
17 .\"O udp \- User Datagram Protocol for IPv4
19 udp \- IPv4 の ユーザーデータグラムプロトコル
22 .B #include <sys/socket.h>
24 .B #include <netinet/in.h>
26 .B udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
29 .\"O This is an implementation of the User Datagram Protocol
30 .\"O described in RFC\ 768.
31 .\"O It implements a connectionless, unreliable datagram packet service.
32 .\"O Packets may be reordered or duplicated before they arrive.
33 .\"O UDP generates and checks checksums to catch transmission errors.
34 これは RFC\ 768 で記述されている User Datagram Protocol の実装である。
35 UDP はコネクションレスの、信頼性の低いデータパケットサービスである。
36 パケットは到着前に並び替えられたり複製されたりする。
37 UDP は転送エラーを検出するためにチェックサムを生成・チェックする。
39 .\"O When a UDP socket is created,
40 .\"O its local and remote addresses are unspecified.
41 .\"O Datagrams can be sent immediately using
45 .\"O with a valid destination address as an argument.
48 .\"O is called on the socket, the default destination address is set and
49 .\"O datagrams can now be sent using
53 .\"O without specifying a destination address.
55 ローカルアドレスやリモートアドレスは指定されない。
60 を呼べば、データグラムはただちに送信される。
63 を呼ぶと、デフォルトの行き先アドレスが設定され、
67 を使って、行き先アドレスの指定なしにデータグラムを送信できるようになる。
68 .\"O It is still possible to send to other destinations by passing an
77 に渡せば、デフォルト以外のアドレスに送信可能である。
78 .\"O In order to receive packets, the socket can be bound to a local
79 .\"O address first by using
83 を用いてローカルなアドレスにバインドさせることもできる。
84 .\"O Otherwise the socket layer will automatically assign
85 .\"O a free local port out of the range defined by
86 .\"O .I /proc/sys/net/ipv4/ip_local_port_range
87 .\"O and bind the socket to
90 .I /proc/sys/net/ipv4/ip_local_port_range
91 で定義されている範囲の外で空いているローカルなポートを割り当て、
96 .\"O All receive operations return only one packet.
97 .\"O When the packet is smaller than the passed buffer, only that much
98 .\"O data is returned, when it is bigger, the packet is truncated and the
101 受信動作はパケットを一つだけ返す。渡したバッファよりもパケットが
102 小さければ、そのパケットの大きさのデータだけが返される。
103 逆にバッファよりも大きい場合はパケットは丸められ、
107 .\"O is not supported.
111 .\"O IP options may be sent or received using the socket options described in
113 .\"O They are only processed by the kernel when the appropriate
116 .\"O is enabled (but still passed to the user even when it is turned off).
121 に記述されているソケットオプションを用いて読み書きできる。
124 パラメータが有効な場合に限ってカーネルによって処理される
125 (しかし無効になっている場合でもユーザーには渡される)。
130 .\"O .B MSG_DONTROUTE
131 .\"O flag is set on sending, the destination address must refer to a local
132 .\"O interface address and the packet is only sent to that interface.
134 フラグが送信時にセットされている場合には、
135 行き先アドレスはローカルなインターフェースアドレスから
136 参照できなければならない。パケットはそのインターフェースにしか送られない。
138 .\"O By default, Linux UDP does path MTU (Maximum Transmission Unit) discovery.
139 .\"O This means the kernel
140 .\"O will keep track of the MTU to a specific target IP address and return
142 .\"O when a UDP packet write exceeds it.
143 .\"O When this happens, the application should decrease the packet size.
144 .\"O Path MTU discovery can be also turned off using the
145 .\"O .B IP_MTU_DISCOVER
146 .\"O socket option or the
147 .\"O .I /proc/sys/net/ipv4/ip_no_pmtu_disc
151 .\"O When turned off, UDP will fragment outgoing UDP packets
152 .\"O that exceed the interface MTU.
153 .\"O However, disabling it is not recommended
154 .\"O for performance and reliability reasons.
155 デフォルトでは、Linux の UDP は Path MTU Discovery を行う。
156 つまり、カーネルは特定の宛先 IP アドレスの MTU (Maximum Transmission Unit;
157 最大転送単位) を記録し、UDP パケットの書き込みが MTU を超えた場合
161 を返された場合、アプリケーションはパケットサイズを小さくすべきである。
165 .I /proc/sys/net/ipv4/ip_no_pmtu_disc
166 ファイルを使って Path MTU Discovery を無効にすることもできる
170 Path MTU Discovery を無効にした場合は、パケットサイズが
171 インタフェースの MTU よりも大きいと UDP はそのパケットを
173 しかしながら、性能と信頼性の理由から Path MTU Discovery を
175 .\"O .SS Address Format
177 .\"O UDP uses the IPv4
179 .\"O address format described in
186 .\"O .SS Error Handling
188 .\"O All fatal errors will be passed to the user as an error return even
189 .\"O when the socket is not connected.
190 .\"O This includes asynchronous errors
191 .\"O received from the network.
192 .\"O You may get an error for an earlier packet
193 .\"O that was sent on the same socket.
194 致命的なエラーは、たとえソケットが接続されていなくても、
195 すべてエラー戻り値としてユーザーに渡される。
196 これにはネットワークから受け取る非同期エラーも含まれる。
197 同じソケットを使って送信した昔のパケットに関するエラーを受け取るかもしれない。
198 .\"O This behavior differs from many other BSD socket implementations
199 .\"O which don't pass any errors unless the socket is connected.
200 .\"O Linux's behavior is mandated by
202 この振る舞いは他の BSD ソケットの実装の多くとは異なる。
203 これらではソケットが接続されていない場合はエラーを全く返さない。
208 .\"O For compatibility with legacy code, in Linux 2.0 and 2.2
209 .\"O it was possible to set the
212 .\"O option to receive remote errors only when the socket has been
213 .\"O connected (except for
217 .\"O Locally generated errors are always passed.
218 .\"O Support for this socket option was removed in later kernels; see
220 .\"O for further information.
221 Linux 2.0 と 2.2 では、古いコードとの互換性のために、
224 オプションを設定すれば、ソケットが接続されている
225 場合に限ってリモートのエラーを受信するようにできた
226 .RB ( EPROTO " と " EMSGSIZE
228 ローカルで生成されたエラーは常に渡される。
229 このソケットオプションのサポートはそれ以降のバージョンの Linux で
236 .\"O option is enabled, all errors are stored in the socket error queue
237 .\"O and can be received by
244 すべてのエラーはソケットのエラーキューに保存される。
250 .\"O .SS /proc interfaces
252 .\"O System-wide UDP parameter settings can be accessed by files in the directory
253 .\"O .IR /proc/sys/net/ipv4/ .
254 システム全体の UDP パラメータ設定には、
255 .I /proc/sys/net/ipv4/
256 ディレクトリ内のファイルの読み書きでアクセスできる。
258 .\"O .IR udp_mem " (since Linux 2.6.25)"
259 .IR udp_mem " (Linux 2.6.25 以降)"
260 .\"O This is a vector of three integers governing the number
261 .\"O of pages allowed for queueing by all UDP sockets.
262 これは 3 つの整数からなるベクトル値で、
263 UDP の全ソケットのキューで利用可能なページ数を制御する。
267 .\"O Below this number of pages, UDP is not bothered about its
268 .\"O memory appetite.
269 .\"O When the amount of memory allocated by UDP exceeds
270 .\"O this number, UDP starts to moderate memory usage.
271 このページ数より少なければ、UDP はそのメモリ使用に関して
273 UDP に割り当てられたメモリ総量がこの値を超過すると、
277 .\"O This value was introduced to follow the format of
288 .\"O Number of pages allowed for queueing by all UDP sockets.
289 UDP の全ソケットのキューで利用可能なページ数。
292 .\"O Defaults values for these three items are
293 .\"O calculated at boot time from the amount of available memory.
295 ブート時に利用可能なメモリ総量から計算される。
297 .\"O .IR udp_rmem_min " (integer; default value: PAGE_SIZE; since Linux 2.6.25)"
298 .IR udp_rmem_min " (integer; デフォルト値: PAGE_SIZE; Linux 2.6.25 以降)"
299 .\"O Minimal size, in bites, of receive buffers used by UDP sockets in moderation.
300 .\"O Each UDP socket is able to use the size for receiving data,
301 .\"O even if total pages of UDP sockets exceed
304 メモリ使用量の調整中に、UDP ソケットが使用できる受信バッファの最小値
306 UDP の全ソケットのページ使用量の合計が
308 pressure を超過している場合であっても、
309 各 UDP ソケットはデータの受信にこのサイズ分だけは使用することができる。
311 .\"O .IR udp_wmem_min " (integer; default value: PAGE_SIZE; since Linux 2.6.25)"
312 .IR udp_wmem_min " (integer; デフォルト値: PAGE_SIZE; Linux 2.6.25 以降)"
313 .\"O Minimal size, in bytes, of send buffer used by UDP sockets in moderation.
314 .\"O Each UDP socket is able to use the size for sending data,
315 .\"O even if total pages of UDP sockets exceed
318 メモリ使用量の調整中に、UDP ソケットが使用できる送信バッファの最小値
320 UDP の全ソケットのページ使用量の合計が
322 pressure を超過している場合であっても、
323 各 UDP ソケットはデータの送信にこのサイズ分だけは使用することができる。
324 .\"O \"O .SS "Socket Options"
326 .\"O To set or get a UDP socket option, call
327 .\"O .BR getsockopt (2)
329 .\"O .BR setsockopt (2)
330 .\"O to write the option with the option level argument set to
331 .\"O .BR IPPROTO_UDP .
332 UDP ソケットオプションを設定または取得するには、
341 .\"O .BR UDP_CORK " (since Linux 2.5.44)"
342 .BR UDP_CORK " (Linux 2.5.44 以降)"
343 .\"O If this option is enabled, then all data output on this socket
344 .\"O is accumulated into a single datagram that is transmitted when
345 .\"O the option is disabled.
346 .\"O This option should not be used in code intended to be
348 このオプションが指定されると、このソケットの全てのデータ出力は
349 一つのデータグラムに蓄積され、このオプションが無効化された時に
351 このオプションは移植性を考慮したコードでは用いるべきではない。
352 .\" FIXME document UDP_ENCAP (new in kernel 2.5.67)
353 .\" From include/linux/udp.h:
354 .\" /* UDP encapsulation types */
355 .\" #define UDP_ENCAP_ESPINUDP_NON_IKE 1 /* draft-ietf-ipsec-nat-t-ike-00/01 */
356 .\" #define UDP_ENCAP_ESPINUDP 2 /* draft-ietf-ipsec-udp-encaps-06 */
357 .\" #define UDP_ENCAP_L2TPINUDP 3 /* rfc2661 */
360 .\"O These ioctls can be accessed using
365 .\"O The correct syntax is:
371 .IB error " = ioctl(" udp_socket ", " ioctl_type ", &" value ");"
375 .BR FIONREAD " (" SIOCINQ )
376 .\"O Gets a pointer to an integer as argument.
377 .\"O Returns the size of the next pending datagram in the integer in bytes,
378 .\"O or 0 when no datagram is pending.
379 integer のポインタを引数として取る。
380 次に待機しているデータグラムのサイズをバイト単位の整数で返す。
381 待機しているデータグラムがない場合は 0 を返す。
383 .BR TIOCOUTQ " (" SIOCOUTQ )
384 .\"O Returns the number of data bytes in the local send queue.
385 .\"O Only supported with Linux 2.4 and above.
386 ローカル送信キューにあるデータサイズをバイト単位で返す。
387 Linux 2.4 以上でのみ対応している。
389 .\"O In addition all ioctls documented in
398 で述べられている全ての ioctl も対応している。
401 .\"O All errors documented for
405 .\"O may be returned by a send or receive on a UDP socket.
410 UDP ソケットの送受信で返される可能性がある。
413 .\"O No receiver was associated with the destination address.
414 .\"O This might be caused by a previous packet sent over the socket.
415 行き先アドレスに関連づけられている受信者がいない。
417 上書き送信してしまっているからであることが多い。
421 .\"O is a new feature in Linux 2.2.
423 は Linux 2.2 の新しい機能である。
426 .\"O .\" This man page was written by Andi Kleen.
427 .\" この man ページは Andi Kleen が書いた。
435 .\"O RFC\ 768 for the User Datagram Protocol.
436 RFC\ 768 : User Datagram Protocol
438 .\"O RFC\ 1122 for the host requirements.
441 .\"O RFC\ 1191 for a description of path MTU discovery.
442 RFC\ 1191 : path MTU discovery の記述