1CONNECT(2)                    System Calls Manual                   CONNECT(2)
2
3
4

NAME

6       connect - initiate a connection on a socket
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <sys/socket.h>
11
12       connect(s, name, namelen)
13       int s;
14       struct sockaddr *name;
15       int namelen;
16

DESCRIPTION

18       The  parameter  s  is a socket.  If it is of type SOCK_DGRAM, then this
19       call specifies the peer with which the socket is to be associated; this
20       address is that to which datagrams are to be sent, and the only address
21       from which datagrams are to be received.  If  the  socket  is  of  type
22       SOCK_STREAM,  then  this  call attempts to make a connection to another
23       socket.  The other socket is specified by name, which is an address  in
24       the  communications  space  of  the  socket.  Each communications space
25       interprets the name parameter in its own way.  Generally, stream  sock‐
26       ets  may  successfully connect only once; datagram sockets may use con‐
27       nect multiple times to change their association.  Datagram sockets  may
28       dissolve the association by connecting to an invalid address, such as a
29       null address.
30

RETURN VALUE

32       If the connection or binding succeeds, then 0 is returned.  Otherwise a
33       -1 is returned, and a more specific error code is stored in errno.
34

ERRORS

36       The call fails if:
37
38       [EBADF]             S is not a valid descriptor.
39
40       [ENOTSOCK]          S is a descriptor for a file, not a socket.
41
42       [EADDRNOTAVAIL]     The  specified  address  is  not  available on this
43                           machine.
44
45       [EAFNOSUPPORT]      Addresses in the specified address family cannot be
46                           used with this socket.
47
48       [EISCONN]           The socket is already connected.
49
50       [ETIMEDOUT]         Connection  establishment  timed out without estab‐
51                           lishing a connection.
52
53       [ECONNREFUSED]      The attempt to connect was forcefully rejected.
54
55       [ENETUNREACH]       The network isn't reachable from this host.
56
57       [EADDRINUSE]        The address is already in use.
58
59       [EFAULT]            The name parameter specifies an  area  outside  the
60                           process address space.
61
62       [EINPROGRESS]       The  socket is non-blocking and the connection can‐
63                           not be completed immediately.  It  is  possible  to
64                           select(2)  for  completion  by selecting the socket
65                           for writing.
66
67       [EALREADY]          The socket is non-blocking and a  previous  connec‐
68                           tion attempt has not yet been completed.
69
70       The  following  errors  are  specific  to  connecting names in the UNIX
71       domain.  These errors may not apply in future versions of the UNIX  IPC
72       domain.
73
74       [ENOTDIR]      A component of the path prefix is not a directory.
75
76       [EINVAL]       The  pathname  contains  a character with the high-order
77                      bit set.
78
79       [ENAMETOOLONG] A component of a pathname exceeded 255 characters, or an
80                      entire path name exceeded 1023 characters.
81
82       [ENOENT]       The named socket does not exist.
83
84       [EACCES]       Search  permission is denied for a component of the path
85                      prefix.
86
87       [EACCES]       Write access to the named socket is denied.
88
89       [ELOOP]        Too many symbolic links were encountered in  translating
90                      the pathname.
91

SEE ALSO

93       accept(2), select(2), socket(2), getsockname(2)
94
95
96
974.2 Berkeley Distribution        May 22, 1986                       CONNECT(2)
Impressum