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