1 .\" Hey Emacs! This file is -*- nroff -*- source.
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.
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.
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.
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
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
28 .\" Other portions are from the 6.9 (Berkeley) 3/10/91 man page:
30 .\" Copyright (c) 1983 The Regents of the University of California.
31 .\" All rights reserved.
33 .\" Redistribution and use in source and binary forms, with or without
34 .\" modification, are permitted provided that the following conditions
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.
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
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>
65 .\" Japanese Version Copyright (c) 1996 Yosiaki Yanagihara
66 .\" all rights reserved.
67 .\" Translated 1996-06-25, Yosiaki Yanagihara <yosiaki@bsd2.kbnes.nec.co.jp>
68 .\" Updated & Modified 1997-11-06, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
69 .\" Updated & Modified 1999-08-14, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
70 .\" Updated & Modified 2000-01-13, Kentaro Shirakata <argrath@yo.rim.or.jp>
71 .\" Updated & Modified 2005-02-23, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
72 .\" Updated & Modified 2005-10-05, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
74 .TH CONNECT 2 2008-12-03 "Linux" "Linux Programmer's Manual"
77 .\"O connect \- initiate a connection on a socket
78 connect \- ¥½¥±¥Ã¥È¤ÎÀܳ¤ò¹Ô¤¦
82 .\"O .BR "#include <sys/types.h>" " /* See NOTES */"
83 .BR "#include <sys/types.h>" " /* ¡ÖÃí°Õ¡×»²¾È */"
85 .B #include <sys/socket.h>
87 .BI "int connect(int " sockfd ", const struct sockaddr *" addr ,
88 .BI " socklen_t " addrlen );
94 .\"O system call connects the socket referred to by the file descriptor
96 .\"O to the address specified by
100 .\"O argument specifies the size of
102 .\"O The format of the address in
104 .\"O is determined by the address space of the socket
108 .\"O for further details.
110 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
112 ¤¬»²¾È¤·¤Æ¤¤¤ë¥½¥±¥Ã¥È¤ò
114 ¤Ç»ØÄꤵ¤ì¤¿¥¢¥É¥ì¥¹¤ËÀܳ¤¹¤ë¡£
120 ¤Î¥¢¥É¥ì¥¹¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ï¥½¥±¥Ã¥È
122 ¤Î¥¢¥É¥ì¥¹¶õ´Ö¤Ë¤è¤ê°Û¤Ê¤ë¡£
133 .\"O is the address to which datagrams are sent by default, and the only
134 .\"O address from which datagrams are received.
135 .\"O If the socket is of type
138 .\"O .BR SOCK_SEQPACKET ,
139 .\"O this call attempts to make a connection to the socket that is bound
140 .\"O to the address specified by
148 ¤Ï¡¢¥Ç¥Õ¥©¥ë¥È¤Î¥Ç¡¼¥¿¥°¥é¥à¤ÎÁ÷¿®Àè¤Î¥¢¥É¥ì¥¹¤Ç¤¢¤ê¡¢
149 ¥Ç¡¼¥¿¥°¥é¥à¤ò¼õ¿®¤¹¤ëÍ£°ì¤Î¥¢¥É¥ì¥¹¤ò¼¨¤¹¤Ë²á¤®¤Ê¤¤¡£
154 ·¿¤Ç¤¢¤ì¤Ð¡¢¤³¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï
156 ¤Ç»ØÄꤵ¤ì¤¿¥¢¥É¥ì¥¹¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤¿¥½¥±¥Ã¥È¤ËÂФ¹¤ëÀܳ¤Î
159 .\"O Generally, connection-based protocol sockets may successfully
161 .\"O only once; connectionless protocol sockets may use
163 .\"O multiple times to change their association.
164 .\"O Connectionless sockets may
165 .\"O dissolve the association by connecting to an address with the
171 .\"O (supported on Linux since kernel 2.2).
172 °ìÈÌŪ¤Ë¡¢Àܳ»Ø¸þ (connection-oriented) ¥×¥í¥È¥³¥ë¤Ç¤Ï°ìÅÙ¤À¤±
175 ÈóÀܳ (connectionless) ¥×¥í¥È¥³¥ë¤Ç¤ÏÂбþ¤òÊѹ¹¤¹¤ë¤¿¤á¤Ë²¿ÅÙ¤â
184 ¤òÀßÄꤹ¤ë¤³¤È¤Ç¡¢Àܳ¥¢¥É¥ì¥¹¤ÎÂбþ¤ò²ò¾Ã¤¹¤ë¤³¤È¤¬¤Ç¤¤ë
186 ¤Ï¥«¡¼¥Í¥ë 2.2 °Ê¹ß¤Î Linux ¤Ç¥µ¥Ý¡¼¥È)¡£
187 .\"O .SH "RETURN VALUE"
189 .\"O If the connection or binding succeeds, zero is returned.
190 .\"O On error, \-1 is
193 .\"O is set appropriately.
194 Àܳ¤Þ¤¿¤ÏÂбþ¤Å¤±¤ËÀ®¸ù¤¹¤ë¤È¥¼¥í¤òÊÖ¤¹¡£
195 ¼ºÇÔ¤¹¤ë¤È \-1 ¤òÊÖ¤·¡¢
197 ¤ËŬÀÚ¤ÊÃͤòÀßÄꤹ¤ë¡£
200 .\"O The following are general socket errors only.
201 .\"O There may be other domain-specific error codes.
202 °Ê²¼¤Ï°ìÈÌŪ¤Ê¥½¥±¥Ã¥È¤Ë¤Ä¤¤¤Æ¤Î¥¨¥é¡¼¤Ç¤¢¤ë¡£Â¾¤Ë¥É¥á¥¤¥óÆÃͤΥ¨¥é¡¼
203 ¤¬È¯À¸¤¹¤ë²ÄǽÀ¤¬¤¢¤ë¡£
206 .\"O For Unix domain sockets, which are identified by pathname:
207 .\"O Write permission is denied on the socket file,
208 .\"O or search permission is denied for one of the directories
209 .\"O in the path prefix.
211 .\"O .BR path_resolution (7).)
212 Unix ¥É¥á¥¤¥ó¥½¥±¥Ã¥È¤Ï¥Ñ¥¹Ì¾¤Ç¼±Ê̤µ¤ì¤ë¡£
213 ¥½¥±¥Ã¥È¡¦¥Õ¥¡¥¤¥ë¤Ø¤Î½ñ¤¹þ¤ßµö²Ä¤¬¤Ê¤«¤Ã¤¿¤«¡¢¥Ñ¥¹Ì¾¤Ø
214 Åþ㤹¤ë¤Þ¤Ç¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Î¤¤¤º¤ì¤«¤ËÂФ¹¤ë¸¡º÷µö²Ä¤¬¤Ê¤«¤Ã¤¿¡£
215 .RB ( path_resolution (7)
218 .BR EACCES ", " EPERM
219 .\"O The user tried to connect to a broadcast address without having the socket
220 .\"O broadcast flag enabled or the connection request failed because of a local
222 ¥½¥±¥Ã¥È¤Î¥Ö¥í¡¼¥É¥¥ã¥¹¥È¡¦¥Õ¥é¥°¤¬Í¸ú¤Ë¤Ê¤Ã¤Æ¤¤¤Ê¤¤¤Î¤Ë
223 ¥æ¡¼¥¶¤¬¥Ö¥í¡¼¥É¥¥ã¥¹¥È¤ØÀܳ¤ò»î¤ß¤¿¡£¤Þ¤¿¤Ï¡¢¥í¡¼¥«¥ë¤Î¥Õ¥¡¥¤¥¢¥¦¥©¡¼¥ë¤Î
224 µ¬Â§¤Ë¤è¤êÀܳ¤ÎÍ׵᤬¼ºÇÔ¤·¤¿¡£
227 .\"O Local address is already in use.
228 ¥í¡¼¥«¥ë¥¢¥É¥ì¥¹¤¬´û¤Ë»ÈÍѤµ¤ì¤Æ¤¤¤ë¡£
231 .\"O The passed address didn't have the correct address family in its
236 ¥Õ¥£¡¼¥ë¥É¤¬Àµ¤·¤¤¥¢¥É¥ì¥¹¡¦¥Õ¥¡¥ß¥ê¡¼¤Ç¤Ï¤Ê¤¤¡£
239 .\"O No more free local ports or insufficient entries in the routing cache.
242 .\"O see the description of
243 .\"O .I /proc/sys/net/ipv4/ip_local_port_range
245 .\"O for information on how to increase the number of local ports.
246 »ÈÍѲÄǽ¤Ê¥í¡¼¥«¥ë¤Î¥Ý¡¼¥È¤¬¤Ê¤¤¤«¡¢
247 ¥ë¡¼¥Æ¥£¥ó¥°¥¥ã¥Ã¥·¥å¤Ë½½Ê¬¤Ê¥¨¥ó¥È¥ê¤¬¤Ê¤¤¡£
249 ¤Î¾ì¹ç¤Ë¡¢¥í¡¼¥«¥ë¥Ý¡¼¥È¤Î¿ô¤òÁý¤ä¤¹ÊýË¡¤Ë¤Ä¤¤¤Æ¤Ï¡¢
252 .I /proc/sys/net/ipv4/ip_local_port_range
256 .\"O The socket is nonblocking and a previous connection attempt has not yet
258 ¥½¥±¥Ã¥È¤¬ÈóÄä»ß (nonblocking) ¤ËÀßÄꤵ¤ì¤Æ¤ª¤ê¡¢
259 Á°¤ÎÀܳ¤¬´°Î»¤·¤Æ¤¤¤Ê¤¤¡£
262 .\"O The file descriptor is not a valid index in the descriptor table.
263 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼¤¬¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼¥Æ¡¼¥Ö¥ë¤Î
264 ͸ú¤Ê¥¤¥ó¥Ç¥Ã¥¯¥¹¤Ç¤Ï¤Ê¤¤¡£
267 .\"O No-one listening on the remote address.
268 ¥ê¥â¡¼¥È¥¢¥É¥ì¥¹¤ÇÀܳ¤òÂԤäƤ¤¤ë¥×¥í¥°¥é¥à¤¬¤Ê¤¤¡£
271 .\"O The socket structure address is outside the user's address space.
272 ¥½¥±¥Ã¥È¹½Â¤ÂΤΥ¢¥É¥ì¥¹¤¬¥æ¡¼¥¶¡¼¤Î¥¢¥É¥ì¥¹¶õ´Ö³°¤Ë¤¢¤ë¡£
275 .\"O The socket is nonblocking and the connection cannot be completed
276 .\"O immediately. It is possible to
280 .\"O for completion by selecting the socket for writing.
283 .\"O indicates writability, use
284 .\"O .BR getsockopt (2)
289 .\"O to determine whether
291 .\"O completed successfully
293 .\"O is zero) or unsuccessfully
295 .\"O is one of the usual error codes listed here,
296 .\"O explaining the reason for the failure).
297 ¥½¥±¥Ã¥È¤¬ÈóÄä»ß (nonblocking) ¤ËÀßÄꤵ¤ì¤Æ¤¤¤Æ¡¢Àܳ¤ò¤¹¤°¤Ë
298 ´°Î»¤¹¤ë¤³¤È¤¬¤Ç¤¤Ê¤¤¡£¤½¤Î¾ì¹ç¡¢
302 ¤ò»È¤Ã¤Æ¤½¤Î¥½¥±¥Ã¥È¤¬½ñ¤¹þ¤ß²Äǽ¤Ë¤Ê¤ë¤Î¤òÂԤĤ³¤È¤Ç¡¢
303 Àܳ¤Î´°Î»¤òÃΤ뤳¤È¤¬¤Ç¤¤ë¡£
305 ¤Ç½ñ¤¹þ¤ß²Äǽ¤Ë¤Ê¤Ã¤¿¸å¤Ë¡¢
311 ¥ª¥×¥·¥ç¥ó¤òÆɤ߽Ф¹¤³
314 ¤¬À®¸ù¤·¤¿¤«¡¢¼ºÇÔ¤·¤¿¤«¤òȽÃǤǤ¤ë¡£
320 ¤¬¤³¤³¤Î¥ê¥¹¥È¤Ë¤¢¤ë¤¤¤º¤ì¤«¤Î¥¨¥é¡¼¥³¡¼¥É¤Ç¤¢¤ê¡¢
321 ¤½¤ì¤Ë¤è¤ê¼ºÇԤθ¶°ø¤¬Ê¬¤«¤ë¡£
324 .\"O The system call was interrupted by a signal that was caught; see
326 .\"O .\" For TCP, the connection will complete asynchronously.
327 .\"O .\" See http://lkml.org/lkml/2005/7/12/254
328 Ê᪤µ¤ì¤¿¥·¥°¥Ê¥ë¤Ë¤è¤ê¥·¥¹¥Æ¥à¥³¡¼¥ë¤¬ÃæÃǤµ¤ì¤¿¡£
331 .\" TCP ¤Î¾ì¹ç¤Ï¡¢Àܳ½èÍý¤ÏÈóƱ´ü¤Ë¤Ê¤ë¤¬´°Î»¤¹¤ë¤À¤í¤¦¡£
332 .\" http://lkml.org/lkml/2005/7/12/254 ¤ò»²¾È¤Î¤³¤È¡£
335 .\"O The socket is already connected.
336 ¥½¥±¥Ã¥È¤Ï´û¤ËÀܳ (connect) ¤µ¤ì¤Æ¤¤¤ë¡£
339 .\"O Network is unreachable.
340 Åþã¤Ç¤¤Ê¤¤¥Í¥Ã¥È¥ï¡¼¥¯¤Ç¤¢¤ë¡£
343 .\"O The file descriptor is not associated with a socket.
344 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼¤¬¥½¥±¥Ã¥È¤È´ØÏ¢ÉÕ¤±¤é¤ì¤Æ¤¤¤Ê¤¤¡£
347 .\"O Timeout while attempting connection.
348 .\"O The server may be too
349 .\"O busy to accept new connections.
350 .\"O Note that for IP sockets the timeout may
351 .\"O be very long when syncookies are enabled on the server.
352 Àܳ¤ò»î¤ß¤Æ¤¤¤ëÅÓÃæ¤Ç»þ´ÖÀÚ¤ì (timeout) ¤Ë¤Ê¤Ã¤¿¡£¥µ¡¼¥Ð¡¼¤¬º®»¨¤·¤Æ¤¤¤Æ
353 ¿·¤¿¤ÊÀܳ¤ò¼õ¤±Æþ¤ì¤é¤ì¤Ê¤¤¤Î¤«¤â¤·¤ì¤Ê¤¤¡£
354 IP ¥½¥±¥Ã¥È¤Ç¤Ï¡¢ syncookie ¤¬¥µ¡¼¥Ð¡¼¤Ç͸ú¤Ë¤Ê¤Ã¤Æ¤¤¤ë¾ì¹ç¡¢
355 ¥¿¥¤¥à¥¢¥¦¥È¤¬Èó¾ï¤ËŤ¯¤Ê¤ë¾ì¹ç¤¬¤¢¤ë¤Î¤ÇÃí°Õ¤¹¤ë¤³¤È¡£
356 .\"O .SH "CONFORMING TO"
358 .\"O SVr4, 4.4BSD, (the
360 .\"O function first appeared in 4.2BSD), POSIX.1-2001.
361 .\"O .\" SVr4 documents the additional
362 .\"O .\" general error codes
363 .\"O .\" .BR EADDRNOTAVAIL ,
364 .\"O .\" .BR EINVAL ,
365 .\"O .\" .BR EAFNOSUPPORT ,
366 .\"O .\" .BR EALREADY ,
368 .\"O .\" .BR EPROTOTYPE ,
373 ´Ø¿ô¤Ï 4.2BSD ¤ÇºÇ½é¤ËÅо줷¤¿), POSIX.1-2001.
374 .\" SVr4 ¤Ç¤Ï¡¢°ìÈÌŪ¤Ê¥¨¥é¡¼¡¦¥³¡¼¥É¤È¤·¤Æ
375 .\" .BR EADDRNOTAVAIL ,
377 .\" .BR EAFNOSUPPORT ,
382 .\" ¤¬Äɲ䵤ì¤Æ¤¤¤ë¡£
384 .\"O .\" documents many additional error conditions not described here.
385 .\" ¤Þ¤¿¡¢Ëܥޥ˥奢¥ë¤Ë¤ÏµºÜ¤·¤Æ¤¤¤Ê¤¤ÄɲäΥ¨¥é¡¼¾ò·ï¤¬Â¿¤¯µºÜ¤µ¤ì¤Æ¤¤¤ë¡£
388 .\"O POSIX.1-2001 does not require the inclusion of
389 .\"O .IR <sys/types.h> ,
390 .\"O and this header file is not required on Linux.
391 .\"O However, some historical (BSD) implementations required this header
392 .\"O file, and portable applications are probably wise to include it.
395 ¤Î¥¤¥ó¥¯¥ë¡¼¥É¤Ïɬ¿Ü¤È¤µ¤ì¤Æ¤ª¤é¤º¡¢
396 Linux ¤Ç¤Ï¤³¤Î¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë¤ÏɬÍפǤϤʤ¤¡£
397 ¤·¤«¤·¡¢Îò»ËŪ¤Ë¤Ï¡¢¤¤¤¯¤Ä¤«¤Î¼ÂÁõ (BSD ·Ï) ¤Ç¤³¤Î¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë¤¬
398 ɬÍפǤ¢¤ê¡¢°Ü¿¢À¤¬É¬Íפʥ¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¤³¤Î¥Õ¥¡¥¤¥ë¤ò
399 ¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤Î¤¬¸ÌÀ¤Ç¤¢¤í¤¦¡£
401 .\"O The third argument of
403 .\"O is in reality an
405 .\"O (and this is what 4.x BSD and libc4 and libc5 have).
406 .\"O Some POSIX confusion resulted in the present
408 .\"O also used by glibc.
412 ¤Î»°ÈÖÌܤΰú¤¿ô¤Ï 4.x BSD ¤ä libc4, libc5 ¤ÈƱÍͤ˼ºݤˤÏ
415 POSIX ¤Ç¤Ïäþ;¶ÊÀÞ¤ò·Ð¤Æ¸½ºß¤Î
425 .\"O An example of the use of
428 .\"O .BR getaddrinfo (3).
440 .BR path_resolution (7)