1 |
27 |
unneback |
.\" $OpenBSD: connect.2,v 1.14 1999/08/15 13:14:11 deraadt Exp $
|
2 |
|
|
.\" $NetBSD: connect.2,v 1.8 1995/10/12 15:40:48 jtc Exp $
|
3 |
|
|
.\"
|
4 |
|
|
.\" Copyright (c) 1983, 1993
|
5 |
|
|
.\" The Regents of the University of California. All rights reserved.
|
6 |
|
|
.\"
|
7 |
|
|
.\" Redistribution and use in source and binary forms, with or without
|
8 |
|
|
.\" modification, are permitted provided that the following conditions
|
9 |
|
|
.\" are met:
|
10 |
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
11 |
|
|
.\" notice, this list of conditions and the following disclaimer.
|
12 |
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
13 |
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
14 |
|
|
.\" documentation and/or other materials provided with the distribution.
|
15 |
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
16 |
|
|
.\" must display the following acknowledgement:
|
17 |
|
|
.\" This product includes software developed by the University of
|
18 |
|
|
.\" California, Berkeley and its contributors.
|
19 |
|
|
.\" 4. Neither the name of the University nor the names of its contributors
|
20 |
|
|
.\" may be used to endorse or promote products derived from this software
|
21 |
|
|
.\" without specific prior written permission.
|
22 |
|
|
.\"
|
23 |
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
24 |
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
25 |
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26 |
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
27 |
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
28 |
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
29 |
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
30 |
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
31 |
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
32 |
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
33 |
|
|
.\" SUCH DAMAGE.
|
34 |
|
|
.\"
|
35 |
|
|
.\" @(#)connect.2 8.1 (Berkeley) 6/4/93
|
36 |
|
|
.\"
|
37 |
|
|
.Dd February 15, 1999
|
38 |
|
|
.Dt CONNECT 2
|
39 |
|
|
.Os
|
40 |
|
|
.Sh NAME
|
41 |
|
|
.Nm connect
|
42 |
|
|
.Nd initiate a connection on a socket
|
43 |
|
|
.Sh SYNOPSIS
|
44 |
|
|
.Fd #include
|
45 |
|
|
.Fd #include
|
46 |
|
|
.Ft int
|
47 |
|
|
.Fn connect "int s" "const struct sockaddr *name" "socklen_t namelen"
|
48 |
|
|
.Sh DESCRIPTION
|
49 |
|
|
The parameter
|
50 |
|
|
.Fa s
|
51 |
|
|
is a socket.
|
52 |
|
|
If it is of type
|
53 |
|
|
.Dv SOCK_DGRAM ,
|
54 |
|
|
this call specifies the peer with which the socket is to be associated;
|
55 |
|
|
this address is that to which datagrams are to be sent,
|
56 |
|
|
and the only address from which datagrams are to be received.
|
57 |
|
|
If the socket is of type
|
58 |
|
|
.Dv SOCK_STREAM ,
|
59 |
|
|
this call attempts to make a connection to
|
60 |
|
|
another socket.
|
61 |
|
|
The other socket is specified by
|
62 |
|
|
.Fa name ,
|
63 |
|
|
which is an address in the communications space of the socket.
|
64 |
|
|
Each communications space interprets the
|
65 |
|
|
.Fa name
|
66 |
|
|
parameter in its own way.
|
67 |
|
|
Generally, stream sockets may successfully
|
68 |
|
|
.Fn connect
|
69 |
|
|
only once; datagram sockets may use
|
70 |
|
|
.Fn connect
|
71 |
|
|
multiple times to change their association.
|
72 |
|
|
Datagram sockets may dissolve the association
|
73 |
|
|
by connecting to an invalid address, such as a null address.
|
74 |
|
|
.Sh RETURN VALUES
|
75 |
|
|
If the connection or binding succeeds, 0 is returned.
|
76 |
|
|
Otherwise a \-1 is returned, and a more specific error
|
77 |
|
|
code is stored in
|
78 |
|
|
.Va errno .
|
79 |
|
|
.Sh ERRORS
|
80 |
|
|
The
|
81 |
|
|
.Fn connect
|
82 |
|
|
call fails if:
|
83 |
|
|
.Bl -tag -width Er
|
84 |
|
|
.It Bq Er EBADF
|
85 |
|
|
.Fa S
|
86 |
|
|
is not a valid descriptor.
|
87 |
|
|
.It Bq Er ENOTSOCK
|
88 |
|
|
.Fa S
|
89 |
|
|
is a descriptor for a file, not a socket.
|
90 |
|
|
.It Bq Er EADDRNOTAVAIL
|
91 |
|
|
The specified address is not available on this machine.
|
92 |
|
|
.It Bq Er EAFNOSUPPORT
|
93 |
|
|
Addresses in the specified address family cannot be used with this socket.
|
94 |
|
|
.It Bq Er EISCONN
|
95 |
|
|
The socket is already connected.
|
96 |
|
|
.It Bq Er ETIMEDOUT
|
97 |
|
|
Connection establishment timed out without establishing a connection.
|
98 |
|
|
.It Bq Er EINVAL
|
99 |
|
|
A TCP connection with a local broadcast, the all-ones or a
|
100 |
|
|
multicast address as the peer was attempted.
|
101 |
|
|
.It Bq Er ECONNREFUSED
|
102 |
|
|
The attempt to connect was forcefully rejected.
|
103 |
|
|
.It Bq Er EINTR
|
104 |
|
|
A connect was interrupted before it succeeded
|
105 |
|
|
by the delivery of a signal.
|
106 |
|
|
.It Bq Er ENETUNREACH
|
107 |
|
|
The network isn't reachable from this host.
|
108 |
|
|
.It Bq Er EADDRINUSE
|
109 |
|
|
The address is already in use.
|
110 |
|
|
.It Bq Er EFAULT
|
111 |
|
|
The
|
112 |
|
|
.Fa name
|
113 |
|
|
parameter specifies an area outside
|
114 |
|
|
the process address space.
|
115 |
|
|
.It Bq Er EINPROGRESS
|
116 |
|
|
The socket is non-blocking
|
117 |
|
|
and the connection cannot
|
118 |
|
|
be completed immediately.
|
119 |
|
|
It is possible to
|
120 |
|
|
.Xr select 2
|
121 |
|
|
or
|
122 |
|
|
.Xr poll 2
|
123 |
|
|
for completion by selecting the socket for writing, and also use
|
124 |
|
|
.Xr getsockopt 2
|
125 |
|
|
with
|
126 |
|
|
.Dv SO_ERROR
|
127 |
|
|
to check for error conditions.
|
128 |
|
|
.It Bq Er EALREADY
|
129 |
|
|
The socket is non-blocking
|
130 |
|
|
and a previous connection attempt
|
131 |
|
|
has not yet been completed.
|
132 |
|
|
.El
|
133 |
|
|
.Pp
|
134 |
|
|
The following errors are specific to connecting names in the UNIX domain.
|
135 |
|
|
These errors may not apply in future versions of the UNIX IPC domain.
|
136 |
|
|
.Bl -tag -width Er
|
137 |
|
|
.It Bq Er ENOTDIR
|
138 |
|
|
A component of the path prefix is not a directory.
|
139 |
|
|
.It Bq Er ENAMETOOLONG
|
140 |
|
|
A component of a pathname exceeded
|
141 |
|
|
.Dv {NAME_MAX}
|
142 |
|
|
characters, or an entire path name exceeded
|
143 |
|
|
.Dv {PATH_MAX}
|
144 |
|
|
characters.
|
145 |
|
|
.It Bq Er ENOENT
|
146 |
|
|
The named socket does not exist.
|
147 |
|
|
.It Bq Er EACCES
|
148 |
|
|
Search permission is denied for a component of the path prefix.
|
149 |
|
|
.It Bq Er EACCES
|
150 |
|
|
Write access to the named socket is denied.
|
151 |
|
|
.It Bq Er ELOOP
|
152 |
|
|
Too many symbolic links were encountered in translating the pathname.
|
153 |
|
|
.El
|
154 |
|
|
.Sh SEE ALSO
|
155 |
|
|
.Xr accept 2 ,
|
156 |
|
|
.Xr getsockname 2 ,
|
157 |
|
|
.Xr getsockopt 2 ,
|
158 |
|
|
.Xr poll 2 ,
|
159 |
|
|
.Xr select 2 ,
|
160 |
|
|
.Xr socket 2
|
161 |
|
|
.Sh HISTORY
|
162 |
|
|
The
|
163 |
|
|
.Fn connect
|
164 |
|
|
function call appeared in
|
165 |
|
|
.Bx 4.2 .
|