1connect(3SOCKET)           Sockets Library Functions          connect(3SOCKET)
2
3
4

NAME

6       connect - initiate a connection on a socket
7

SYNOPSIS

9       cc [ flag ... ] file ... -lsocket  -lnsl  [ library ... ]
10       #include <sys/types.h>
11       #include <sys/socket.h>
12
13
14
15       int connect(int s, const struct sockaddr *name, int namelen);
16
17

DESCRIPTION

19       The  parameter  s  is  a socket. If it is of type SOCK_DGRAM, connect()
20       specifies the peer with which the socket  is  to  be  associated.  This
21       address  is the address to which datagrams are to be sent if a receiver
22       is not explicitly designated. This address is  the  only  address  from
23       which  datagrams  are  to  be  received.  If  the  socket  s is of type
24       SOCK_STREAM, connect() attempts to make a connection to another socket.
25       The other socket is specified by name. name is an address in the commu‐
26       nication space of the socket. Each communication space  interprets  the
27       name  parameter in its own way. If s is not bound, then s will be bound
28       to an address selected by the underlying transport provider. Generally,
29       stream  sockets  can successfully connect() only once. Datagram sockets
30       can use connect() multiple times to change their association.  Datagram
31       sockets can dissolve the association by connecting to a null address.
32

RETURN VALUES

34       If  the connection or binding succeeds, 0 is returned. Otherwise, −1 is
35       returned and sets errno to indicate the error.
36

ERRORS

38       The call fails if:
39
40       EACCES           Search permission is denied for  a  component  of  the
41                        path prefix of the pathname in name.
42
43
44       EADDRINUSE       The address is already in use.
45
46
47       EADDRNOTAVAIL    The  specified  address is not available on the remote
48                        machine.
49
50
51       EAFNOSUPPORT     Addresses in the specified address  family  cannot  be
52                        used with this socket.
53
54
55       EALREADY         The socket is non-blocking,  and a previous connection
56                        attempt has not yet been completed.
57
58
59       EBADF            s is not a valid descriptor.
60
61
62       ECONNREFUSED     The attempt to connect was  forcefully  rejected.  The
63                        calling program should close(2) the socket descriptor,
64                        and issue another socket(3SOCKET) call to obtain a new
65                        descriptor before attempting another connect() call.
66
67
68       EINPROGRESS      The  socket is non-blocking, and the connection cannot
69                        be completed immediately. You can use   select(3C)  to
70                        complete  the  connection  by selecting the socket for
71                        writing.
72
73
74       EINTR            The connection attempt was interrupted before any data
75                        arrived  by  the delivery of a signal. The connection,
76                        however, will be established asynchronously.
77
78
79       EINVAL           namelen is not the size of a  valid  address  for  the
80                        specified address family.
81
82
83       EIO              An I/O error occurred while reading from or writing to
84                        the file system.
85
86
87       EISCONN          The socket is already connected.
88
89
90       ELOOP            Too many symbolic links were encountered in  translat‐
91                        ing the pathname in name.
92
93
94       ENETUNREACH      The network is not reachable from this host.
95
96
97       EHOSTUNREACH     The remote host is not reachable from this host.
98
99
100       ENOENT           A component of the path prefix of the pathname in name
101                        does not exist.
102
103
104       ENOENT           The socket referred to by the pathname  in  name  does
105                        not exist.
106
107
108       ENOSR            There were insufficient STREAMS resources available to
109                        complete the operation.
110
111
112       ENXIO            The server exited before the connection was complete.
113
114
115       ETIMEDOUT        Connection establishment timed out without  establish‐
116                        ing a connection.
117
118
119       EWOULDBLOCK      The   socket   is  marked  as  non-blocking,  and  the
120                        requested operation would block.
121
122
123
124       The following errors are specific  to  connecting  names  in  the  UNIX
125       domain.   These  errors  might not apply in future versions of the UNIX
126       IPC domain.
127
128       ENOTDIR       A component of the path prefix of the pathname in name is
129                     not a directory.
130
131
132       ENOTSOCK      s is not a socket.
133
134
135       ENOTSOCK      name is not a socket.
136
137
138       EPROTOTYPE    The  file  that  is  referred to by name is a socket of a
139                     type other than type s. For example, s  is  a  SOCK_DGRAM
140                     socket, while name refers to a SOCK_STREAM socket.
141
142

ATTRIBUTES

144       See attributes(5) for descriptions of the following attributes:
145
146
147
148
149       ┌─────────────────────────────┬─────────────────────────────┐
150       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
151       ├─────────────────────────────┼─────────────────────────────┤
152       │MT-Level                     │Safe                         │
153       └─────────────────────────────┴─────────────────────────────┘
154

SEE ALSO

156       close(2),     accept(3SOCKET),     getsockname(3SOCKET),    select(3C),
157       socket(3SOCKET), socket.h(3HEAD), attributes(5)
158
159
160
161SunOS 5.11                        08 Mar 2005                 connect(3SOCKET)
Impressum