136759Sbostic.\" Copyright (c) 1983 The Regents of the University of California. 236759Sbostic.\" All rights reserved. 320211Smckusick.\" 443568Strent.\" %sccs.include.redist.man% 520211Smckusick.\" 6*47208Scael.\" @(#)connect.2 6.9 (Berkeley) 03/10/91 736759Sbostic.\" 8*47208Scael.Dd 9*47208Scael.Dt CONNECT 2 10*47208Scael.Os BSD 4.2 11*47208Scael.Sh NAME 12*47208Scael.Nm connect 13*47208Scael.Nd initiate a connection on a socket 14*47208Scael.Sh SYNOPSIS 15*47208Scael.Fd #include <sys/types.h> 16*47208Scael.Fd #include <sys/socket.h> 17*47208Scael.Ft int 18*47208Scael.Fn connect "int s" "struct sockaddr *name" "int namelen" 19*47208Scael.Sh DESCRIPTION 2020211SmckusickThe parameter 21*47208Scael.Fa s 2220211Smckusickis a socket. 23*47208ScaelIf it is of type 24*47208Scael.Dv SOCK_DGRAM , 25*47208Scaelthis call specifies the peer with which the socket is to be associated; 2628064Skarelsthis address is that to which datagrams are to be sent, 2728064Skarelsand the only address from which datagrams are to be received. 28*47208ScaelIf the socket is of type 29*47208Scael.Dv SOCK_STREAM , 30*47208Scaelthis call attempts to make a connection to 3120211Smckusickanother socket. 3220211SmckusickThe other socket is specified by 33*47208Scael.Fa name , 3420211Smckusickwhich is an address in the communications space of the socket. 3520211SmckusickEach communications space interprets the 36*47208Scael.Fa name 3720211Smckusickparameter in its own way. 3828064SkarelsGenerally, stream sockets may successfully 39*47208Scael.Fn connect 4028064Skarelsonly once; datagram sockets may use 41*47208Scael.Fn connect 4228064Skarelsmultiple times to change their association. 4328064SkarelsDatagram sockets may dissolve the association 4428064Skarelsby connecting to an invalid address, such as a null address. 45*47208Scael.Sh RETURN VALUES 46*47208ScaelIf the connection or binding succeeds, 0 is returned. 47*47208ScaelOtherwise a -1 is returned, and a more specific error 48*47208Scaelcode is stored in 49*47208Scael.Va errno . 50*47208Scael.Sh ERRORS 51*47208ScaelThe 52*47208Scael.Fn connect 53*47208Scaelcall fails if: 54*47208Scael.Bl -tag -width EADDRNOTAVAILABB 55*47208Scael.It Bq Er EBADF 56*47208Scael.Fa S 5720211Smckusickis not a valid descriptor. 58*47208Scael.It Bq Er ENOTSOCK 59*47208Scael.Fa S 6020211Smckusickis a descriptor for a file, not a socket. 61*47208Scael.It Bq Er EADDRNOTAVAIL 6220211SmckusickThe specified address is not available on this machine. 63*47208Scael.It Bq Er EAFNOSUPPORT 6420211SmckusickAddresses in the specified address family cannot be used with this socket. 65*47208Scael.It Bq Er EISCONN 6620211SmckusickThe socket is already connected. 67*47208Scael.It Bq Er ETIMEDOUT 6820211SmckusickConnection establishment timed out without establishing a connection. 69*47208Scael.It Bq Er ECONNREFUSED 7020211SmckusickThe attempt to connect was forcefully rejected. 71*47208Scael.It Bq Er ENETUNREACH 7220211SmckusickThe network isn't reachable from this host. 73*47208Scael.It Bq Er EADDRINUSE 7420211SmckusickThe address is already in use. 75*47208Scael.It Bq Er EFAULT 76*47208ScaelThe 77*47208Scael.Fa name 78*47208Scaelparameter specifies an area outside 7920211Smckusickthe process address space. 80*47208Scael.It Bq Er EINPROGRESS 8128362SanneThe socket is non-blocking 8220211Smckusickand the connection cannot 8320211Smckusickbe completed immediately. 8420211SmckusickIt is possible to 85*47208Scael.Xr select 2 8628145Skarelsfor completion by selecting the socket for writing. 87*47208Scael.It Bq Er EALREADY 8828064SkarelsThe socket is non-blocking 8928064Skarelsand a previous connection attempt 9028362Sannehas not yet been completed. 91*47208Scael.El 92*47208Scael.Pp 9321004SmckusickThe following errors are specific to connecting names in the UNIX domain. 9428064SkarelsThese errors may not apply in future versions of the UNIX IPC domain. 95*47208Scael.Bl -tag -width EADDRNOTAVAILABB 96*47208Scael.It Bq Er ENOTDIR 9721004SmckusickA component of the path prefix is not a directory. 98*47208Scael.It Bq Er EINVAL 9921004SmckusickThe pathname contains a character with the high-order bit set. 100*47208Scael.It Bq Er ENAMETOOLONG 10121004SmckusickA component of a pathname exceeded 255 characters, 10221004Smckusickor an entire path name exceeded 1023 characters. 103*47208Scael.It Bq Er ENOENT 10421004SmckusickThe named socket does not exist. 105*47208Scael.It Bq Er EACCES 10621004SmckusickSearch permission is denied for a component of the path prefix. 107*47208Scael.It Bq Er EACCES 10828064SkarelsWrite access to the named socket is denied. 109*47208Scael.It Bq Er ELOOP 11021004SmckusickToo many symbolic links were encountered in translating the pathname. 111*47208Scael.El 112*47208Scael.Sh SEE ALSO 113*47208Scael.Xr accept 2 , 114*47208Scael.Xr select 2 , 115*47208Scael.Xr socket 2 , 116*47208Scael.Xr getsockname 2 117*47208Scael.Sh HISTORY 118*47208ScaelThe 119*47208Scael.Nm 120*47208Scaelfunction call appeared in 121*47208Scael.Bx 4.2 . 122