<html>
|
<html>
|
<body>
|
<body>
|
<pre>
|
<pre>
|
NAME
|
NAME
|
connect - initiate a connection on a socket
|
connect - initiate a connection on a socket
|
|
|
SYNOPSIS
|
SYNOPSIS
|
#include <network.h>
|
#include <network.h>
|
|
|
int connect(int sockfd, struct sockaddr *serv_addr, int
|
int connect(int sockfd, struct sockaddr *serv_addr, int
|
addrlen);
|
addrlen);
|
|
|
DESCRIPTION
|
DESCRIPTION
|
The parameter sockfd is a socket. If the socket is of
|
The parameter sockfd is a socket. If the socket is of
|
type SOCK_DGRAM, this call specifies the peer with which
|
type SOCK_DGRAM, this call specifies the peer with which
|
the socket is to be associated; this address is that to
|
the socket is to be associated; this address is that to
|
which datagrams are to be sent, and the only address from
|
which datagrams are to be sent, and the only address from
|
which datagrams are to be received. If the socket is of
|
which datagrams are to be received. If the socket is of
|
type SOCK_STREAM, this call attempts to make a connection
|
type SOCK_STREAM, this call attempts to make a connection
|
to another socket. The other socket is specified by
|
to another socket. The other socket is specified by
|
serv_addr, which is an address in the communications space
|
serv_addr, which is an address in the communications space
|
of the socket. Each communications space interprets the
|
of the socket. Each communications space interprets the
|
serv_addr parameter in its own way. Generally, stream
|
serv_addr parameter in its own way. Generally, stream
|
sockets may successfully connect only once; datagram sock-
|
sockets may successfully connect only once; datagram sock-
|
ets may use connect multiple times to change their associ-
|
ets may use connect multiple times to change their associ-
|
ation. Datagram sockets may dissolve the association by
|
ation. Datagram sockets may dissolve the association by
|
connecting to an address with the sa_family sockaddr mem-
|
connecting to an address with the sa_family sockaddr mem-
|
ber set to AF_UNSPEC.
|
ber set to AF_UNSPEC.
|
|
|
RETURN VALUE
|
RETURN VALUE
|
If the connection or binding succeeds, zero is returned.
|
If the connection or binding succeeds, zero is returned.
|
On error, -1 is returned, and errno is set appropriately.
|
On error, -1 is returned, and errno is set appropriately.
|
|
|
ERRORS
|
ERRORS
|
The following are general socket errors only. There may
|
The following are general socket errors only. There may
|
be other domain-specific error codes.
|
be other domain-specific error codes.
|
|
|
EBADF Bad descriptor.
|
EBADF Bad descriptor.
|
|
|
ENOTSOCK
|
ENOTSOCK
|
The descriptor is not associated with a socket.
|
The descriptor is not associated with a socket.
|
|
|
EISCONN The socket is already connected.
|
EISCONN The socket is already connected.
|
|
|
ECONNREFUSED
|
ECONNREFUSED
|
Connection refused at server.
|
Connection refused at server.
|
|
|
ETIMEDOUT
|
ETIMEDOUT
|
Timeout while attempting connection.
|
Timeout while attempting connection.
|
|
|
ENETUNREACH
|
ENETUNREACH
|
Network is unreachable.
|
Network is unreachable.
|
|
|
EADDRINUSE
|
EADDRINUSE
|
Address is already in use.
|
Address is already in use.
|
|
|
EINPROGRESS
|
EINPROGRESS
|
The socket is non-blocking and the connection can-
|
The socket is non-blocking and the connection can-
|
not be completed immediately. It is possible to
|
not be completed immediately. It is possible to
|
select(2) or poll(2) for completion by selecting
|
select(2) or poll(2) for completion by selecting
|
the socket for writing. After select indicates
|
the socket for writing. After select indicates
|
writability, use getsockopt(2) to read the
|
writability, use getsockopt(2) to read the
|
SO_ERROR option at level SOL_SOCKET to determine
|
SO_ERROR option at level SOL_SOCKET to determine
|
whether connect completed successfully (SO_ERROR
|
whether connect completed successfully (SO_ERROR
|
is zero) or unsuccessfully (SO_ERROR is one of the
|
is zero) or unsuccessfully (SO_ERROR is one of the
|
usual error codes listed above, explaining the
|
usual error codes listed above, explaining the
|
reason for the failure).
|
reason for the failure).
|
|
|
EALREADY
|
EALREADY
|
The socket is non-blocking and a previous connec-
|
The socket is non-blocking and a previous connec-
|
tion attempt has not yet been completed.
|
tion attempt has not yet been completed.
|
|
|
EAFNOSUPPORT
|
EAFNOSUPPORT
|
The passed address didn't have the correct address
|
The passed address didn't have the correct address
|
family in its sa_family field.
|
family in its sa_family field.
|
|
|
EACCES The user tried to connect to a broadcast address
|
EACCES The user tried to connect to a broadcast address
|
without having the socket broadcast flag enabled.
|
without having the socket broadcast flag enabled.
|
</pre>
|
</pre>
|
</body>
|
</body>
|
</html>
|
</html>
|
|
|