xref: /csrg-svn/lib/libc/sys/connect.2 (revision 61181)
1*61181Sbostic.\" Copyright (c) 1983, 1993
2*61181Sbostic.\"	The Regents of the University of California.  All rights reserved.
320211Smckusick.\"
443568Strent.\" %sccs.include.redist.man%
520211Smckusick.\"
6*61181Sbostic.\"     @(#)connect.2	8.1 (Berkeley) 06/04/93
736759Sbostic.\"
847208Scael.Dd
947208Scael.Dt CONNECT 2
1047208Scael.Os BSD 4.2
1147208Scael.Sh NAME
1247208Scael.Nm connect
1347208Scael.Nd initiate a connection on a socket
1447208Scael.Sh SYNOPSIS
1547208Scael.Fd #include <sys/types.h>
1647208Scael.Fd #include <sys/socket.h>
1747208Scael.Ft int
1847208Scael.Fn connect "int s" "struct sockaddr *name" "int namelen"
1947208Scael.Sh DESCRIPTION
2020211SmckusickThe parameter
2147208Scael.Fa s
2220211Smckusickis a socket.
2347208ScaelIf it is of type
2447208Scael.Dv SOCK_DGRAM ,
2547208Scaelthis 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.
2847208ScaelIf the socket is of type
2947208Scael.Dv SOCK_STREAM ,
3047208Scaelthis call attempts to make a connection to
3120211Smckusickanother socket.
3220211SmckusickThe other socket is specified by
3347208Scael.Fa name ,
3420211Smckusickwhich is an address in the communications space of the socket.
3520211SmckusickEach communications space interprets the
3647208Scael.Fa name
3720211Smckusickparameter in its own way.
3828064SkarelsGenerally, stream sockets may successfully
3947208Scael.Fn connect
4028064Skarelsonly once; datagram sockets may use
4147208Scael.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.
4547208Scael.Sh RETURN VALUES
4647208ScaelIf the connection or binding succeeds, 0 is returned.
4747208ScaelOtherwise a -1 is returned, and a more specific error
4847208Scaelcode is stored in
4947208Scael.Va errno .
5047208Scael.Sh ERRORS
5147208ScaelThe
5247208Scael.Fn connect
5347208Scaelcall fails if:
5447208Scael.Bl -tag -width EADDRNOTAVAILABB
5547208Scael.It Bq Er EBADF
5647208Scael.Fa S
5720211Smckusickis not a valid descriptor.
5847208Scael.It Bq Er ENOTSOCK
5947208Scael.Fa S
6020211Smckusickis a descriptor for a file, not a socket.
6147208Scael.It Bq Er EADDRNOTAVAIL
6220211SmckusickThe specified address is not available on this machine.
6347208Scael.It Bq Er EAFNOSUPPORT
6420211SmckusickAddresses in the specified address family cannot be used with this socket.
6547208Scael.It Bq Er EISCONN
6620211SmckusickThe socket is already connected.
6747208Scael.It Bq Er ETIMEDOUT
6820211SmckusickConnection establishment timed out without establishing a connection.
6947208Scael.It Bq Er ECONNREFUSED
7020211SmckusickThe attempt to connect was forcefully rejected.
7147208Scael.It Bq Er ENETUNREACH
7220211SmckusickThe network isn't reachable from this host.
7347208Scael.It Bq Er EADDRINUSE
7420211SmckusickThe address is already in use.
7547208Scael.It Bq Er EFAULT
7647208ScaelThe
7747208Scael.Fa name
7847208Scaelparameter specifies an area outside
7920211Smckusickthe process address space.
8047208Scael.It Bq Er EINPROGRESS
8128362SanneThe socket is non-blocking
8220211Smckusickand the connection cannot
8320211Smckusickbe completed immediately.
8420211SmckusickIt is possible to
8547208Scael.Xr select 2
8628145Skarelsfor completion by selecting the socket for writing.
8747208Scael.It Bq Er EALREADY
8828064SkarelsThe socket is non-blocking
8928064Skarelsand a previous connection attempt
9028362Sannehas not yet been completed.
9147208Scael.El
9247208Scael.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.
9547208Scael.Bl -tag -width EADDRNOTAVAILABB
9647208Scael.It Bq Er ENOTDIR
9721004SmckusickA component of the path prefix is not a directory.
9847208Scael.It Bq Er EINVAL
9921004SmckusickThe pathname contains a character with the high-order bit set.
10047208Scael.It Bq Er ENAMETOOLONG
10121004SmckusickA component of a pathname exceeded 255 characters,
10221004Smckusickor an entire path name exceeded 1023 characters.
10347208Scael.It Bq Er ENOENT
10421004SmckusickThe named socket does not exist.
10547208Scael.It Bq Er EACCES
10621004SmckusickSearch permission is denied for a component of the path prefix.
10747208Scael.It Bq Er EACCES
10828064SkarelsWrite access to the named socket is denied.
10947208Scael.It Bq Er ELOOP
11021004SmckusickToo many symbolic links were encountered in translating the pathname.
11147208Scael.El
11247208Scael.Sh SEE ALSO
11347208Scael.Xr accept 2 ,
11447208Scael.Xr select 2 ,
11547208Scael.Xr socket 2 ,
11647208Scael.Xr getsockname 2
11747208Scael.Sh HISTORY
11847208ScaelThe
11947208Scael.Nm
12047208Scaelfunction call appeared in
12147208Scael.Bx 4.2 .
122