Initiate a connection on a socket
#include <sys/types.h> #include <sys/socket.h> int connect( int s, const struct sockaddr * name, socklen_t namelen );
- The descriptor of the socket on which to initiate the connection.
- The name of the socket to connect to for a SOCK_STREAM connection.
- The length of the name, in bytes.
Use the -l socket option to qcc to link against this library.
The connect() function establishes the connection according to the socket type specified by s:
- Specifies the peer that the socket is to be associated with. This address is the one that datagrams are to be sent to, and the only one that datagrams are to be received from.
- This call attempts to make a connection to another socket. The other socket is specified by name, which is an address in the communications space of that socket. Each communications space interprets name in its own way.
Stream sockets may successfully connect only once, whereas datagram sockets may use connect() multiple times to change their association. Datagram sockets may dissolve the association by connecting to an invalid address, such as a null address.
- An error occurred (errno is set).
- The address is already in use.
- The specified address isn't available on this machine.
- Addresses in the specified address family cannot be used with this socket.
- The socket is nonblocking; a previous connection attempt hasn't yet been completed.
- Invalid descriptor s.
- The connect() was terminated under software control.
- The attempt to connect was forcefully rejected.
- The name parameter specifies an area outside the process address space.
- No route to host; the host system can't be reached.
- The socket is nonblocking; the connection can't be completed immediately. It's possible to do a select() for completion by selecting the socket for writing.
- The socket is already connected.
- The network isn't reachable from this host.
- The attempt to establish a connection timed out; no connection was made.