2 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\" must display the following acknowledgement:
15 .\" This product includes software developed by the University of
16 .\" California, Berkeley and its contributors.
17 .\" 4. Neither the name of the University nor the names of its contributors
18 .\" may be used to endorse or promote products derived from this software
19 .\" without specific prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" $Id: socket.2,v 1.4 1999/05/13 11:33:42 freitag Exp $
35 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
36 .\" Modified 1996-10-22 by Eric S. Raymond <esr@thyrsus.com>
37 .\" Modified 1998, 1999 by Andi Kleen <ak@muc.de>
38 .\" Modified 2002-07-17 by Michael Kerrisk <mtk.manpages@gmail.com>
39 .\" Modified 2004-06-17 by Michael Kerrisk <mtk.manpages@gmail.com>
41 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
42 .\" all rights reserved.
43 .\" Translated Mon Mar 3 23:40:11 JST 1997
44 .\" by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
45 .\" Modified Sun Aug 15 23:52:28 JST 1999
46 .\" by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
47 .\" Updated Mon Jan 13 JST 2000 by Kentaro Shirakata <argrath@ub32.org>
48 .\" Updated Mon Oct 15 JST 2001 by Kentaro Shirakata <argrath@ub32.org>
49 .\" Updated Mon Oct 26 JST 2002 by Kentaro Shirakata <argrath@ub32.org>
50 .\" Updated 2008-11-09, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.13
53 .\"WORD: descriptor ディスクリプター
54 .\"WORD: link layer リンク層
55 .\"WORD: byte stream バイト・ストリーム
56 .\"WORD: out-of-band 帯域外
57 .\"WORD: sequenced 順序性のある
58 .\"WORD: reliable 信頼性のある
60 .\"WORD: datagram データグラム
62 .\"WORD: super-user スーパー・ユーザー
63 .\"WORD: full-duplex 全二重
64 .\"WORD: non-blocking I/O 非停止 I/O
65 .\"WORD: asynchronous 非同期
67 .TH SOCKET 2 2009-01-19 "Linux" "Linux Programmer's Manual"
70 .\"O socket \- create an endpoint for communication
71 socket \- 通信のための端点(endpoint)を作成する
74 .\"O .BR "#include <sys/types.h>" " /* See NOTES */"
75 .BR "#include <sys/types.h>" " /* 「注意」参照 */"
77 .B #include <sys/socket.h>
79 .BI "int socket(int " domain ", int " type ", int " protocol );
83 .\"O creates an endpoint for communication and returns a descriptor.
85 は通信のための端点(endpoint)を作成し、ディスクリプター(descriptor)を返す。
89 .\"O argument specifies a communication domain; this selects the protocol
90 .\"O family which will be used for communication.
91 .\"O These families are defined in
92 .\"O .IR <sys/socket.h> .
93 .\"O The currently understood formats include:
95 引数は通信を行なうドメインを指定する; これはどの
96 プロトコル・ファミリ(protocol family)を通信に使用するかを指定する。
100 現在、理解できるフォーマットは以下の通り。
104 .\"O Name:Purpose:Man page
107 .BR AF_UNIX ", " AF_LOCAL
109 .\"O Local communication
116 .\"O T}:IPv4 Internet protocols:T{
117 T}:IPv4 インターネット・プロトコル:T{
122 .\"O T}:IPv6 Internet protocols:T{
123 T}:IPv6 インターネット・プロトコル:T{
128 .\"O T}:IPX \- Novell protocols:
129 T}:IPX \- Novell プロトコル:
133 .\"O Kernel user interface device
140 .\"O T}:ITU-T X.25 / ISO-8208 protocol:T{
141 T}:ITU-T X.25 / ISO-8208 プロトコル:T{
147 .\"O Amateur radio AX.25 protocol
152 .\"O T}:Access to raw ATM PVCs:
153 T}:生の ATM PVC にアクセスする:
163 .\"O Low level packet interface
170 .\"O The socket has the indicated
172 .\"O which specifies the communication semantics.
173 .\"O Currently defined types
177 で指定される型を持ち、それは通信方式(semantics)を指定する。
181 .\"O Provides sequenced, reliable, two-way, connection-based byte streams.
182 .\"O An out-of-band data transmission mechanism may be supported.
183 順序性と信頼性があり、双方向の、接続された
184 バイト・ストリーム(byte stream)を提供する。
185 帯域外(out-of-band)データ転送メカニズムもサポートされる。
188 .\"O Supports datagrams (connectionless, unreliable messages of a fixed
189 .\"O maximum length).
190 データグラム(接続、信頼性無し、固定最大長メッセージ)
194 .\"O Provides a sequenced, reliable, two-way connection-based data
195 .\"O transmission path for datagrams of fixed maximum length; a consumer is
196 .\"O required to read an entire packet with each input system call.
197 固定最大長のデータグラム転送パスに基づいた順序性、信頼性のある
198 双方向の接続に基づいた通信を提供する。受け取り側ではそれぞれの入力
199 システム・コールでパケット全体を読み取ることが要求される。
202 .\"O Provides raw network protocol access.
203 生のネットワーク・プロトコルへのアクセスを提供する。
206 .\"O Provides a reliable datagram layer that does not guarantee ordering.
207 信頼性はあるが、順序は保証しないデータグラム層を提供する。
210 .\"O Obsolete and should not be used in new programs;
213 廃止されており新しいプログラムで使用してはいけない。
217 .\"O Some socket types may not be implemented by all protocol families;
219 .\"O .B SOCK_SEQPACKET
220 .\"O is not implemented for
222 ある種のソケット型が全てのプロトコル・ファミリで実装されているわけではない。
229 .\"O Since Linux 2.6.27, the
231 .\"O argument serves a second purpose:
232 .\"O in addition to specifying a socket type,
233 .\"O it may include the bitwise OR of any of the following values,
234 .\"O to modify the behavior of
240 以下の値のいくつかをビット単位の論理和 (OR) で指定することで、
247 .\"O file status flag on the new open file description.
248 .\"O Using this flag saves extra calls to
250 .\"O to achieve the same result.
251 新しく生成されるオープンファイル記述 (open file description) の
261 .\"O Set the close-on-exec
262 .\"O .RB ( FD_CLOEXEC )
263 .\"O flag on the new file descriptor.
264 .\"O See the description of the
268 .\"O for reasons why this may be useful.
281 .\"O specifies a particular protocol to be used with the socket.
282 .\"O Normally only a single protocol exists to support a particular
283 .\"O socket type within a given protocol family, in which case
285 .\"O can be specified as 0.
286 .\"O However, it is possible that many protocols may exist, in
287 .\"O which case a particular protocol must be specified in this manner.
288 .\"O The protocol number to use is specific to the \*(lqcommunication domain\*(rq
289 .\"O in which communication is to take place; see
290 .\"O .BR protocols (5).
292 .\"O .BR getprotoent (3)
293 .\"O on how to map protocol name strings to protocol numbers.
295 はソケットによって使用される固有のプロトコルを指定する。通常それぞれの
296 ソケットは、与えられたプロトコル・ファミリの種類ごとに一つのプロトコルのみを
301 しかし、多くのプロトコルが存在してもかまわない。
302 この場合にはこの方法により固有のプロトコルを指定する必要がある。
303 使用されるプロトコル番号は通信の行なわれる\*(lq通信ドメイン\*(rqに
307 プロトコル名をどうやってプロトコル番号に対応させるかについては
313 .\"O are full-duplex byte streams, similar to pipes.
314 .\"O They do not preserve
315 .\"O record boundaries.
316 .\"O A stream socket must be in
319 .\"O state before any data may be sent or received on it.
321 .\"O another socket is created with a
324 .\"O Once connected, data may be transferred using
328 .\"O calls or some variant of the
333 .\"O When a session has been completed a
335 .\"O may be performed.
336 .\"O Out-of-band data may also be transmitted as described in
338 .\"O and received as described in
341 型のソケットはパイプのような全二重バイト・ストリームである。
343 ストリームは、ソケットがデータを送ったり受けたりする前に
345 状態になってなければならない。他のソケットへの接続は
347 コールによって行なわれる。一度接続したらデータは
365 .\"O The communications protocols which implement a
367 .\"O ensure that data is not lost or duplicated.
368 .\"O If a piece of data for which
369 .\"O the peer protocol has buffer space cannot be successfully transmitted
370 .\"O within a reasonable length of time, then the connection is considered
374 .\"O is enabled on the socket the protocol checks in a protocol-specific
375 .\"O manner if the other end is still alive.
377 を実装した通信プロトコルはデータに損失や重複がないことを保証する。
378 もし相手のプロトコルがバッファー空間を持つ
379 データの断片を適当な時間のうちに転送できなければ、
382 が有効になっている場合、プロトコル独自の方法で接続の相手側がまだ
386 .\"O signal is raised if a process sends or receives
387 .\"O on a broken stream; this causes naive processes,
388 .\"O which do not handle the signal, to exit.
389 もしプロセスが、壊れたストリームでデータを送受信しようとした場合には
391 シグナルが送られる; これは通常のそのシグナルを扱っていないプロセスを
393 .\"O .B SOCK_SEQPACKET
394 .\"O sockets employ the same system calls as
397 .\"O The only difference is that
399 .\"O calls will return only the amount of data requested,
400 .\"O and any data remaining in the arriving packet will be discarded.
401 .\"O Also all message boundaries in incoming datagrams are preserved.
405 ソケットと同じシステム・コールを使用する。
408 コールが要求された量のデータのみを返し、到着したパケットの残りの部分を
409 捨ててしまうことである。同様に入ってくるデータグラムの全てのメッセージ境界は
415 .\"O sockets allow sending of datagrams to correspondents named in
418 .\"O Datagrams are generally received with
419 .\"O .BR recvfrom (2),
420 .\"O which returns the next datagram along with the address of its sender.
426 コールで指定された相手へデータグラムを送ることが許されている。
430 このコールは次のデータグラムを送信者のアドレスと一緒に返す。
433 .\"O is an obsolete socket type to receive raw packets directly from the
439 は古いソケット型で、生(raw)のパケットをデバイスドライバから
448 .\"O operation can be used to specify a process or process group to receive a
450 .\"O signal when the out-of-band data arrives or
454 .\"O connection breaks unexpectedly.
462 を受けとるプロセス・グループを指定できる。
469 .\"O This operation may also be used to set the process or process group
470 .\"O that receives the I/O and asynchronous notification of I/O events via
474 操作は、I/O や I/O イベントの非同期 (asynchronous) 通知を
476 を経由で受け取るプロセスやプロセス・グループを設定するのにも使用できる。
479 .\"O is equivalent to an
495 .\"O When the network signals an error condition to the protocol module (e.g.,
496 .\"O using a ICMP message for IP) the pending error flag is set for the socket.
497 .\"O The next operation on this socket will return the error code of the pending
499 .\"O For some protocols it is possible to enable a per-socket error queue
500 .\"O to retrieve detailed information about the error; see
504 ネットワークがプロトコル・モジュールにエラー状態を伝えた場合
505 (例えば、IP の ICMP メッセージを使用して)には、ソケットの
506 ペンディング・エラー・フラグが設定される。次にこのソケットを操作した
507 時にペンディングされていたエラー・コードが返される。プロトコルによっては
508 エラーについてのより詳しい情報を受け取るためにソケットごとのエラー・キューを
515 .\"O The operation of sockets is controlled by socket level
517 .\"O These options are defined in
518 .\"O .IR <sys/socket.h> .
520 .\"O .BR setsockopt (2)
522 .\"O .BR getsockopt (2)
523 .\"O are used to set and get options, respectively.
533 関数はそれぞれオプションの設定と取得を行なう。
534 .\"O .SH "RETURN VALUE"
536 .\"O On success, a file descriptor for the new socket is returned.
537 .\"O On error, \-1 is returned, and
539 .\"O is set appropriately.
540 成功した場合、新しいソケットのファイル・ディスクリプターを返す。
548 .\"O Permission to create a socket of the specified type and/or protocol
550 指定されたタイプまたはプロトコルのソケットを作成する許可が与えられていない。
553 .\"O The implementation does not support the specified address family.
554 指定されたアドレスファミリーがサポートされていない。
557 .\"O Unknown protocol, or protocol family not available.
558 知らないプロトコル、または利用できないプロトコル・ファミリである。
561 .\" Since Linux 2.6.27
562 .\"O Invalid flags in
568 .\"O Process file table overflow.
572 .\"O The system limit on the total number of open files has been reached.
573 オープンされたファイルの総数がシステム上限に達している。
575 .\"O .BR ENOBUFS " or " ENOMEM
576 .BR ENOBUFS " または " ENOMEM
577 .\"O Insufficient memory is available.
578 .\"O The socket cannot be
579 .\"O created until sufficient resources are freed.
580 十分なメモリがない。十分な資源が解放されるまではソケットを
584 .\"O The protocol type or the specified protocol is not
585 .\"O supported within this domain.
586 このドメインでは指定されたプロトコルまたはプロトコル・タイプが
589 .\"O Other errors may be generated by the underlying protocol modules.
590 下位のプロトコル・モジュールから他のエラーが生成されるかもしれない。
591 .\"O .SH "CONFORMING TO"
593 4.4BSD, POSIX.1-2001.
596 .\"O .B SOCK_NONBLOCK
599 .\"O flags are Linux-specific.
606 .\"O appeared in 4.2BSD.
607 .\"O It is generally portable to/from
608 .\"O non-BSD systems supporting clones of the BSD socket layer (including
609 .\"O System V variants).
611 は 4.2BSD で登場した。一般に、(System V の変種を含めて)
612 BSD のソケット層の互換性をサポートしている BSD 以外のシステムへの、
613 または、BSD 以外のシステムからの移植ができる。
616 .\"O POSIX.1-2001 does not require the inclusion of
617 .\"O .IR <sys/types.h> ,
618 .\"O and this header file is not required on Linux.
619 .\"O However, some historical (BSD) implementations required this header
620 .\"O file, and portable applications are probably wise to include it.
624 Linux ではこのヘッダファイルは必要ではない。
625 しかし、歴史的には、いくつかの実装 (BSD 系) でこのヘッダファイルが
626 必要であり、移植性が必要なアプリケーションではこのファイルを
629 .\"O The manifest constants used under 4.x BSD for protocol families
635 .\"O etc. are used for address
637 .\"O However, already the BSD man page promises: "The protocol
638 .\"O family generally is the same as the address family", and subsequent
639 .\"O standards use AF_* everywhere.
640 4.x BSD において定数を使用する場合、プロトコル・ファミリーには
643 等を使用している。一方でアドレス・ファミリーには
645 等が使用されている。しかしながら BSD のマニュアルでは
646 「一般にプロトコル・ファミリーはアドレス・ファミリーと同じものである。」
647 と保証している。それでそれ以外の規格では全ての場所で AF_* が使用されている。
650 .\"O An example of the use of
653 .\"O .BR getaddrinfo (3).
683 .\"O \(lqAn Introductory 4.3BSD Interprocess Communication Tutorial\(rq
685 .\"O .I UNIX Programmer's Supplementary Documents Volume 1.
686 \(lqAn Introductory 4.3BSD Interprocess Communication Tutorial\(rq
688 .I UNIX Programmer's Supplementary Documents Volume 1
691 .\"O \(lqBSD Interprocess Communication Tutorial\(rq
693 .\"O .I UNIX Programmer's Supplementary Documents Volume 1.
694 \(lqBSD Interprocess Communication Tutorial\(rq
696 .I UNIX Programmer's Supplementary Documents Volume 1