OSDN Git Service

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