OSDN Git Service

(split) LDP: Update the version to 3.53 in PO files
[linuxjm/LDP_man-pages.git] / release / 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 .TH CONNECT 2 2008\-12\-03 Linux "Linux Programmer's Manual"
73 .SH 名前
74 connect \- ソケットの接続を行う
75 .SH 書式
76 .nf
77 \fB#include <sys/types.h>\fP          /* 「注意」参照 */
78 .br
79 \fB#include <sys/socket.h>\fP
80 .sp
81 \fBint connect(int \fP\fIsockfd\fP\fB, const struct sockaddr *\fP\fIaddr\fP\fB,\fP
82 \fB            socklen_t \fP\fIaddrlen\fP\fB);\fP
83 .fi
84 .SH 説明
85 \fBconnect\fP()  システムコールは、ファイルディスクリプタ \fIsockfd\fP が参照しているソケットを \fIaddr\fP
86 で指定されたアドレスに接続する。 \fIaddrlen\fP 引き数は \fIaddr\fP の大きさを示す。 \fIaddr\fP のアドレスのフォーマットはソケット
87 \fIsockfd\fP のアドレス空間により異なる。 さらなる詳細は \fBsocket\fP(2)  を参照のこと。
88
89 ソケット \fIsockfd\fP が \fBSOCK_DGRAM\fP 型であれば、 \fIaddr\fP は、デフォルトのデータグラムの送信先のアドレスであり、
90 データグラムを受信する唯一のアドレスを示すに過ぎない。 ソケットが \fBSOCK_STREAM\fP 型もしくは \fBSOCK_SEQPACKET\fP
91 型であれば、このシステムコールは \fIaddr\fP で指定されたアドレスに結び付けられたソケットに対する接続の 作成を試みる。
92 .PP
93 一般的に、接続指向 (connection\-oriented) プロトコルでは一度だけ \fBconnect\fP()  が成功する。 コネクションレス
94 (connectionless) プロトコルでは対応を変更するために何度も \fBconnect\fP()  を使用できる。 非接続ソケットは
95 \fIsockaddr\fP の \fIsa_family\fP メンバに \fBAF_UNSPEC\fP を設定することで、接続アドレスの対応を解消することができる
96 (\fBAF_UNSPEC\fP はカーネル 2.2 以降の Linux でサポート)。
97 .SH 返り値
98 接続または対応づけに成功するとゼロを返す。 失敗すると \-1 を返し、 \fIerrno\fP に適切な値を設定する。
99 .SH エラー
100 以下は一般的なソケットについてのエラーである。他にドメイン特有のエラー が発生する可能性がある。
101 .TP 
102 \fBEACCES\fP
103 UNIX ドメインソケットはパス名で識別される。 ソケット・ファイルへの書き込み許可がなかったか、パス名へ
104 到達するまでのディレクトリのいずれかに対する検索許可がなかった。 (\fBpath_resolution\fP(7)  も参照のこと)
105 .TP 
106 \fBEACCES\fP, \fBEPERM\fP
107 ソケットのブロードキャスト・フラグが有効になっていないのに ユーザがブロードキャストへ接続を試みた。または、ローカルのファイアウォールの
108 規則により接続の要求が失敗した。
109 .TP 
110 \fBEADDRINUSE\fP
111 ローカルアドレスが既に使用されている。
112 .TP 
113 \fBEAFNOSUPPORT\fP
114 渡されたアドレスの \fIsa_family\fP フィールドが正しいアドレス・ファミリーではない。
115 .TP 
116 \fBEAGAIN\fP
117 使用可能なローカルのポートがないか、 ルーティングキャッシュに十分なエントリがない。 \fBAF_INET\fP
118 の場合に、ローカルポートの数を増やす方法については、 \fBip\fP(7)  の
119 \fI/proc/sys/net/ipv4/ip_local_port_range\fP の説明を参照のこと。
120 .TP 
121 \fBEALREADY\fP
122 ソケットが非停止 (nonblocking) に設定されており、 前の接続が完了していない。
123 .TP 
124 \fBEBADF\fP
125 ファイルディスクリプターがディスクリプターテーブルの 有効なインデックスではない。
126 .TP 
127 \fBECONNREFUSED\fP
128 リモートアドレスで接続を待っているプログラムがない。
129 .TP 
130 \fBEFAULT\fP
131 ソケット構造体のアドレスがユーザーのアドレス空間外にある。
132 .TP 
133 \fBEINPROGRESS\fP
134 ソケットが非停止 (nonblocking) に設定されていて、接続をすぐに 完了することができない。その場合、 \fBselect\fP(2)  や
135 \fBpoll\fP(2)  を使ってそのソケットが書き込み可能になるのを待つことで、 接続の完了を知ることができる。 \fBselect\fP(2)
136 で書き込み可能になった後に、 \fBgetsockopt\fP(2)  を使って \fBSOL_SOCKET\fP レベルで \fBSO_ERROR\fP
137 オプションを読み出すこ とにより、 \fBconnect\fP()  が成功したか、失敗したかを判断できる。 成功の場合 \fBSO_ERROR\fP が 0
138 であり、 失敗の場合 \fBSO_ERROR\fP がここのリストにあるいずれかのエラーコードであり、 それにより失敗の原因が分かる。
139 .TP 
140 \fBEINTR\fP
141 .\" For TCP, the connection will complete asynchronously.
142 .\" See http://lkml.org/lkml/2005/7/12/254
143 捕捉されたシグナルによりシステムコールが中断された。 \fBsignal\fP(7)  参照。
144 .TP 
145 \fBEISCONN\fP
146 ソケットは既に接続 (connect) されている。
147 .TP 
148 \fBENETUNREACH\fP
149 到達できないネットワークである。
150 .TP 
151 \fBENOTSOCK\fP
152 ファイルディスクリプターがソケットと関連付けられていない。
153 .TP 
154 \fBETIMEDOUT\fP
155 接続を試みている途中で時間切れ (timeout) になった。サーバーが混雑していて 新たな接続を受け入れられないのかもしれない。 IP ソケットでは、
156 syncookie がサーバーで有効になっている場合、 タイムアウトが非常に長くなる場合があるので注意すること。
157 .SH 準拠
158 .\" SVr4 documents the additional
159 .\" general error codes
160 .\" .BR EADDRNOTAVAIL ,
161 .\" .BR EINVAL ,
162 .\" .BR EAFNOSUPPORT ,
163 .\" .BR EALREADY ,
164 .\" .BR EINTR ,
165 .\" .BR EPROTOTYPE ,
166 .\" and
167 .\" .BR ENOSR .
168 .\" It also
169 .\" documents many additional error conditions not described here.
170 SVr4, 4.4BSD, (\fBconnect\fP()  関数は 4.2BSD で最初に登場した), POSIX.1\-2001.
171 .SH 注意
172 POSIX.1\-2001 では \fI<sys/types.h>\fP のインクルードは必須とされておらず、 Linux
173 ではこのヘッダファイルは必要ではない。 しかし、歴史的には、いくつかの実装 (BSD 系) でこのヘッダファイルが
174 必要であり、移植性が必要なアプリケーションではこのファイルを インクルードするのが賢明であろう。
175
176 \fBconnect\fP()  の三番目の引き数は 4.x BSD や libc4, libc5 と同様に実際には \fIint\fP である。 POSIX
177 では紆余曲折を経て現在の \fIsocklen_t\fP になっており、 glibc でも \fIsocklen_t\fP を使っている。 \fBaccept\fP(2)
178 も参照のこと。
179 .SH 例
180 \fBconnect\fP()  の利用例が \fBgetaddrinfo\fP(3)  に記載されている。
181 .SH 関連項目
182 \fBaccept\fP(2), \fBbind\fP(2), \fBgetsockname\fP(2), \fBlisten\fP(2), \fBsocket\fP(2),
183 \fBpath_resolution\fP(7)
184 .SH この文書について
185 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
186 である。プロジェクトの説明とバグ報告に関する情報は
187 http://www.kernel.org/doc/man\-pages/ に書かれている。