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. Neither the name of the University nor the names of its contributors 13.\" may be used to endorse or promote products derived from this software 14.\" without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.\" @(#)connect.2 8.1 (Berkeley) 6/4/93 29.\" $FreeBSD: src/lib/libc/sys/connect.2,v 1.11.2.8 2003/04/05 16:59:01 ceri Exp $ 30.\" $DragonFly: src/lib/libc/sys/connect.2,v 1.3 2007/07/30 22:11:33 swildner Exp $ 31.\" 32.Dd June 4, 1993 33.Dt CONNECT 2 34.Os 35.Sh NAME 36.Nm connect 37.Nd initiate a connection on a socket 38.Sh LIBRARY 39.Lb libc 40.Sh SYNOPSIS 41.In sys/types.h 42.In sys/socket.h 43.Ft int 44.Fn connect "int s" "const struct sockaddr *name" "socklen_t namelen" 45.Sh DESCRIPTION 46The parameter 47.Fa s 48is a socket. 49If it is of type 50.Dv SOCK_DGRAM , 51this call specifies the peer with which the socket is to be associated; 52this address is that to which datagrams are to be sent, 53and the only address from which datagrams are to be received. 54If the socket is of type 55.Dv SOCK_STREAM , 56this call attempts to make a connection to 57another socket. 58The other socket is specified by 59.Fa name , 60which is an address in the communications space of the socket. 61Each communications space interprets the 62.Fa name 63parameter in its own way. 64Generally, stream sockets may successfully 65.Fn connect 66only once; datagram sockets may use 67.Fn connect 68multiple times to change their association. 69Datagram sockets may dissolve the association 70by connecting to an invalid address, such as a null address. 71.Sh RETURN VALUES 72.Rv -std connect 73.Sh ERRORS 74The 75.Fn connect 76call fails if: 77.Bl -tag -width Er 78.It Bq Er EBADF 79.Fa s 80is not a valid descriptor. 81.It Bq Er ENOTSOCK 82.Fa s 83is a descriptor for a file, not a socket. 84.It Bq Er EADDRNOTAVAIL 85The specified address is not available on this machine. 86.It Bq Er EAFNOSUPPORT 87Addresses in the specified address family cannot be used with this socket. 88.It Bq Er EISCONN 89The socket is already connected. 90.It Bq Er ETIMEDOUT 91Connection establishment timed out without establishing a connection. 92.It Bq Er ECONNREFUSED 93The attempt to connect was forcefully rejected. 94.It Bq Er ENETUNREACH 95The network is not reachable from this host. 96.It Bq Er EHOSTUNREACH 97The remote host is not reachable from this host. 98.It Bq Er EADDRINUSE 99The address is already in use. 100.It Bq Er EFAULT 101The 102.Fa name 103parameter specifies an area outside 104the process address space. 105.It Bq Er EINPROGRESS 106The socket is non-blocking 107and the connection cannot 108be completed immediately. 109It is possible to 110.Xr select 2 111for completion by selecting the socket for writing. 112.It Bq Er EALREADY 113The socket is non-blocking 114and a previous connection attempt 115has not yet been completed. 116.El 117.Pp 118The following errors are specific to connecting names in the 119.Ux 120domain. 121These errors may not apply in future versions of the 122.Ux 123IPC 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