OSDN Git Service

Update drafts for LDP 3.67
[linuxjm/LDP_man-pages.git] / draft / man2 / connect.2
1 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu)
2 .\" Portions extracted from /usr/include/sys/socket.h, which does not have
3 .\" any authorship information in it.  It is probably available under the GPL.
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
26 .\"
27 .\"
28 .\" Other portions are from the 6.9 (Berkeley) 3/10/91 man page:
29 .\"
30 .\" Copyright (c) 1983 The Regents of the University of California.
31 .\" All rights reserved.
32 .\"
33 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
34 .\" Redistribution and use in source and binary forms, with or without
35 .\" modification, are permitted provided that the following conditions
36 .\" are met:
37 .\" 1. Redistributions of source code must retain the above copyright
38 .\"    notice, this list of conditions and the following disclaimer.
39 .\" 2. Redistributions in binary form must reproduce the above copyright
40 .\"    notice, this list of conditions and the following disclaimer in the
41 .\"    documentation and/or other materials provided with the distribution.
42 .\" 3. All advertising materials mentioning features or use of this software
43 .\"    must display the following acknowledgement:
44 .\"     This product includes software developed by the University of
45 .\"     California, Berkeley and its contributors.
46 .\" 4. Neither the name of the University nor the names of its contributors
47 .\"    may be used to endorse or promote products derived from this software
48 .\"    without specific prior written permission.
49 .\"
50 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 .\" SUCH DAMAGE.
61 .\" %%%LICENSE_END
62 .\"
63 .\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
64 .\" Modified 1998, 1999 by Andi Kleen
65 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
66 .\"
67 .\"*******************************************************************
68 .\"
69 .\" This file was generated with po4a. Translate the source file.
70 .\"
71 .\"*******************************************************************
72 .\"
73 .\" Japanese Version Copyright (c) 1996 Yosiaki Yanagihara
74 .\"         all rights reserved.
75 .\" Translated 1996-06-25, Yosiaki Yanagihara <yosiaki@bsd2.kbnes.nec.co.jp>
76 .\" Updated & Modified 1997-11-06, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
77 .\" Updated & Modified 1999-08-14, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
78 .\" Updated & Modified 2000-01-13, Kentaro Shirakata <argrath@yo.rim.or.jp>
79 .\" Updated & Modified 2005-02-23, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
80 .\" Updated & Modified 2005-10-05, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
81 .\"
82 .TH CONNECT 2 2014\-05\-10 Linux "Linux Programmer's Manual"
83 .SH 名前
84 connect \- ソケットの接続を行う
85 .SH 書式
86 .nf
87 \fB#include <sys/types.h>\fP          /* 「注意」参照 */
88 .br
89 \fB#include <sys/socket.h>\fP
90 .sp
91 \fBint connect(int \fP\fIsockfd\fP\fB, const struct sockaddr *\fP\fIaddr\fP\fB,\fP
92 \fB            socklen_t \fP\fIaddrlen\fP\fB);\fP
93 .fi
94 .SH 説明
95 \fBconnect\fP()  システムコールは、ファイルディスクリプタ \fIsockfd\fP が参照しているソケットを \fIaddr\fP
96 で指定されたアドレスに接続する。 \fIaddrlen\fP 引き数は \fIaddr\fP の大きさを示す。 \fIaddr\fP のアドレスのフォーマットはソケット
97 \fIsockfd\fP のアドレス空間により異なる。 さらなる詳細は \fBsocket\fP(2)  を参照のこと。
98
99 ソケット \fIsockfd\fP が \fBSOCK_DGRAM\fP 型であれば、 \fIaddr\fP は、デフォルトのデータグラムの送信先のアドレスであり、
100 データグラムを受信する唯一のアドレスを示すに過ぎない。 ソケットが \fBSOCK_STREAM\fP 型もしくは \fBSOCK_SEQPACKET\fP
101 型であれば、このシステムコールは \fIaddr\fP で指定されたアドレスに結び付けられたソケットに対する接続の 作成を試みる。
102 .PP
103 一般的に、接続指向 (connection\-oriented) プロトコルでは一度だけ \fBconnect\fP()  が成功する。 コネクションレス
104 (connectionless) プロトコルでは対応を変更するために何度も \fBconnect\fP()  を使用できる。 非接続ソケットは
105 \fIsockaddr\fP の \fIsa_family\fP メンバに \fBAF_UNSPEC\fP を設定することで、接続アドレスの対応を解消することができる
106 (\fBAF_UNSPEC\fP はカーネル 2.2 以降の Linux でサポート)。
107 .SH 返り値
108 接続または対応づけに成功するとゼロを返す。 失敗すると \-1 を返し、 \fIerrno\fP に適切な値を設定する。
109 .SH エラー
110 以下は一般的なソケットについてのエラーである。他にドメイン特有のエラー が発生する可能性がある。
111 .TP 
112 \fBEACCES\fP
113 UNIX ドメインソケットはパス名で識別される。 ソケット・ファイルへの書き込み許可がなかったか、パス名へ
114 到達するまでのディレクトリのいずれかに対する検索許可がなかった。 (\fBpath_resolution\fP(7)  も参照のこと)
115 .TP 
116 \fBEACCES\fP, \fBEPERM\fP
117 ソケットのブロードキャスト・フラグが有効になっていないのに ユーザがブロードキャストへ接続を試みた。または、ローカルのファイアウォールの
118 規則により接続の要求が失敗した。
119 .TP 
120 \fBEADDRINUSE\fP
121 ローカルアドレスが既に使用されている。
122 .TP 
123 \fBEADDRNOTAVAIL\fP
124 (インターネットドメインソケットの場合) \fIsockfd\fP が参照するソケットがそれ以前にアドレスにバインドされておらず、
125 そのソケットに一時ポートをバインドしようとした際に、 一時ポートとして使用する範囲のポート番号がすべて使用中であった。 \fBip\fP(7) の
126 \fI/proc/sys/net/ipv4/ip_local_port_range\fP の議論を参照のこと。
127 .TP 
128 \fBEAFNOSUPPORT\fP
129 渡されたアドレスの \fIsa_family\fP フィールドが正しいアドレス・ファミリーではない。
130 .TP 
131 \fBEAGAIN\fP
132 ルーティングキャッシュにエントリーが十分にない。
133 .TP 
134 \fBEALREADY\fP
135 ソケットが非停止 (nonblocking) に設定されており、 前の接続が完了していない。
136 .TP 
137 \fBEBADF\fP
138 ファイルディスクリプターがディスクリプターテーブルの 有効なインデックスではない。
139 .TP 
140 \fBECONNREFUSED\fP
141 リモートアドレスで接続を待っているプログラムがない。
142 .TP 
143 \fBEFAULT\fP
144 ソケット構造体のアドレスがユーザーのアドレス空間外にある。
145 .TP 
146 \fBEINPROGRESS\fP
147 ソケットが非停止 (nonblocking) に設定されていて、接続をすぐに 完了することができない。その場合、 \fBselect\fP(2)  や
148 \fBpoll\fP(2)  を使ってそのソケットが書き込み可能になるのを待つことで、 接続の完了を知ることができる。 \fBselect\fP(2)
149 で書き込み可能になった後に、 \fBgetsockopt\fP(2)  を使って \fBSOL_SOCKET\fP レベルで \fBSO_ERROR\fP
150 オプションを読み出すこ とにより、 \fBconnect\fP()  が成功したか、失敗したかを判断できる。 成功の場合 \fBSO_ERROR\fP が 0
151 であり、 失敗の場合 \fBSO_ERROR\fP がここのリストにあるいずれかのエラーコードであり、 それにより失敗の原因が分かる。
152 .TP 
153 \fBEINTR\fP
154 .\" For TCP, the connection will complete asynchronously.
155 .\" See http://lkml.org/lkml/2005/7/12/254
156 捕捉されたシグナルによりシステムコールが中断された。 \fBsignal\fP(7)  参照。
157 .TP 
158 \fBEISCONN\fP
159 ソケットは既に接続 (connect) されている。
160 .TP 
161 \fBENETUNREACH\fP
162 到達できないネットワークである。
163 .TP 
164 \fBENOTSOCK\fP
165 ファイルディスクリプターがソケットと関連付けられていない。
166 .TP 
167 \fBETIMEDOUT\fP
168 接続を試みている途中で時間切れ (timeout) になった。サーバーが混雑していて 新たな接続を受け入れられないのかもしれない。 IP ソケットでは、
169 syncookie がサーバーで有効になっている場合、 タイムアウトが非常に長くなる場合があるので注意すること。
170 .SH 準拠
171 .\" SVr4 documents the additional
172 .\" general error codes
173 .\" .BR EADDRNOTAVAIL ,
174 .\" .BR EINVAL ,
175 .\" .BR EAFNOSUPPORT ,
176 .\" .BR EALREADY ,
177 .\" .BR EINTR ,
178 .\" .BR EPROTOTYPE ,
179 .\" and
180 .\" .BR ENOSR .
181 .\" It also
182 .\" documents many additional error conditions not described here.
183 SVr4, 4.4BSD, (\fBconnect\fP()  関数は 4.2BSD で最初に登場した), POSIX.1\-2001.
184 .SH 注意
185 POSIX.1\-2001 では \fI<sys/types.h>\fP のインクルードは必須とされておらず、 Linux
186 ではこのヘッダファイルは必要ではない。 しかし、歴史的には、いくつかの実装 (BSD 系) でこのヘッダファイルが
187 必要であり、移植性が必要なアプリケーションではこのファイルを インクルードするのが賢明であろう。
188
189 \fBconnect\fP()  の三番目の引き数は 4.x BSD や libc4, libc5 と同様に実際には \fIint\fP である。 POSIX
190 では紆余曲折を経て現在の \fIsocklen_t\fP になっており、 glibc でも \fIsocklen_t\fP を使っている。 \fBaccept\fP(2)
191 も参照のこと。
192 .SH 例
193 \fBconnect\fP()  の利用例が \fBgetaddrinfo\fP(3)  に記載されている。
194 .SH 関連項目
195 \fBaccept\fP(2), \fBbind\fP(2), \fBgetsockname\fP(2), \fBlisten\fP(2), \fBsocket\fP(2),
196 \fBpath_resolution\fP(7)
197 .SH この文書について
198 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.67 の一部
199 である。プロジェクトの説明とバグ報告に関する情報は
200 http://www.kernel.org/doc/man\-pages/ に書かれている。