OSDN Git Service

(split) LDP: Restore and add Copyrights for draft pages
[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 2008\-12\-03 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 \fBEAFNOSUPPORT\fP
124 渡されたアドレスの \fIsa_family\fP フィールドが正しいアドレス・ファミリーではない。
125 .TP 
126 \fBEAGAIN\fP
127 使用可能なローカルのポートがないか、 ルーティングキャッシュに十分なエントリがない。 \fBAF_INET\fP
128 の場合に、ローカルポートの数を増やす方法については、 \fBip\fP(7)  の
129 \fI/proc/sys/net/ipv4/ip_local_port_range\fP の説明を参照のこと。
130 .TP 
131 \fBEALREADY\fP
132 ソケットが非停止 (nonblocking) に設定されており、 前の接続が完了していない。
133 .TP 
134 \fBEBADF\fP
135 ファイルディスクリプターがディスクリプターテーブルの 有効なインデックスではない。
136 .TP 
137 \fBECONNREFUSED\fP
138 リモートアドレスで接続を待っているプログラムがない。
139 .TP 
140 \fBEFAULT\fP
141 ソケット構造体のアドレスがユーザーのアドレス空間外にある。
142 .TP 
143 \fBEINPROGRESS\fP
144 ソケットが非停止 (nonblocking) に設定されていて、接続をすぐに 完了することができない。その場合、 \fBselect\fP(2)  や
145 \fBpoll\fP(2)  を使ってそのソケットが書き込み可能になるのを待つことで、 接続の完了を知ることができる。 \fBselect\fP(2)
146 で書き込み可能になった後に、 \fBgetsockopt\fP(2)  を使って \fBSOL_SOCKET\fP レベルで \fBSO_ERROR\fP
147 オプションを読み出すこ とにより、 \fBconnect\fP()  が成功したか、失敗したかを判断できる。 成功の場合 \fBSO_ERROR\fP が 0
148 であり、 失敗の場合 \fBSO_ERROR\fP がここのリストにあるいずれかのエラーコードであり、 それにより失敗の原因が分かる。
149 .TP 
150 \fBEINTR\fP
151 .\" For TCP, the connection will complete asynchronously.
152 .\" See http://lkml.org/lkml/2005/7/12/254
153 捕捉されたシグナルによりシステムコールが中断された。 \fBsignal\fP(7)  参照。
154 .TP 
155 \fBEISCONN\fP
156 ソケットは既に接続 (connect) されている。
157 .TP 
158 \fBENETUNREACH\fP
159 到達できないネットワークである。
160 .TP 
161 \fBENOTSOCK\fP
162 ファイルディスクリプターがソケットと関連付けられていない。
163 .TP 
164 \fBETIMEDOUT\fP
165 接続を試みている途中で時間切れ (timeout) になった。サーバーが混雑していて 新たな接続を受け入れられないのかもしれない。 IP ソケットでは、
166 syncookie がサーバーで有効になっている場合、 タイムアウトが非常に長くなる場合があるので注意すること。
167 .SH 準拠
168 .\" SVr4 documents the additional
169 .\" general error codes
170 .\" .BR EADDRNOTAVAIL ,
171 .\" .BR EINVAL ,
172 .\" .BR EAFNOSUPPORT ,
173 .\" .BR EALREADY ,
174 .\" .BR EINTR ,
175 .\" .BR EPROTOTYPE ,
176 .\" and
177 .\" .BR ENOSR .
178 .\" It also
179 .\" documents many additional error conditions not described here.
180 SVr4, 4.4BSD, (\fBconnect\fP()  関数は 4.2BSD で最初に登場した), POSIX.1\-2001.
181 .SH 注意
182 POSIX.1\-2001 では \fI<sys/types.h>\fP のインクルードは必須とされておらず、 Linux
183 ではこのヘッダファイルは必要ではない。 しかし、歴史的には、いくつかの実装 (BSD 系) でこのヘッダファイルが
184 必要であり、移植性が必要なアプリケーションではこのファイルを インクルードするのが賢明であろう。
185
186 \fBconnect\fP()  の三番目の引き数は 4.x BSD や libc4, libc5 と同様に実際には \fIint\fP である。 POSIX
187 では紆余曲折を経て現在の \fIsocklen_t\fP になっており、 glibc でも \fIsocklen_t\fP を使っている。 \fBaccept\fP(2)
188 も参照のこと。
189 .SH 例
190 \fBconnect\fP()  の利用例が \fBgetaddrinfo\fP(3)  に記載されている。
191 .SH 関連項目
192 \fBaccept\fP(2), \fBbind\fP(2), \fBgetsockname\fP(2), \fBlisten\fP(2), \fBsocket\fP(2),
193 \fBpath_resolution\fP(7)
194 .SH この文書について
195 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
196 である。プロジェクトの説明とバグ報告に関する情報は
197 http://www.kernel.org/doc/man\-pages/ に書かれている。