CONNECT(2) — Series 300 and 800 Only
NAME
connect − initiate a connection on a socket
SYNOPSIS
#include <sys/types.h>
#include <sys/socket.h>
connect(s, addr, addrlen)
int s;
struct sockaddr *addr;
int addrlen;
DESCRIPTION
The parameter s is a socket descriptor. Addr is a pointer to a socket address structure. This structure contains the address of a remote socket to which a connection will be established. Addrlen is the size of this address structure.
If the socket is of type SOCK_DGRAM, then connect permanently specifies the remote socket (peer) to which messages are to be sent, and the call returns immediately. Furthermore, this socket is no longer capable of receiving messages sent from sockets other than its peer.
If the socket is of type SOCK_STREAM, then connect attempts to contact the remote host in order to make a connection between the remote socket (peer) and the local socket specified by s. The call normally blocks until the connection completes. If the socket is in non-blocking mode (see socket(7)), then an EINPROGRESS error is returned by the call. In this case, the select(2) call can be used on this socket to determine when the connection has completed by selecting it for writing.
If s is a SOCK_STREAM socket that is bound to the same local address as another SOCK_STREAM socket, connect returns EADDRINUSE if addr is the same as the peer address of that other socket. This situation can only happen if the SO_REUSEADDR option has been set on this socket (see socket(2)).
If the socket does not already have a local name bound to it (see bind(2)), the connect call also binds the socket to a local address chosen by the system.
RETURN VALUE
If the call is successful, 0 is returned. If it fails, −1 is returned and an error code is stored in errno.
DIAGNOSTICS
The connect call fails if:
[EBADF] s is not a valid file descriptor.
[ENOTSOCK] s is a file descriptor for a file, not a socket.
[EADDRNOTAVAIL] The specified address is not available on this machine.
[EAFNOSUPPORT] Addresses in the specified address family cannot be used with this socket.
[EISCONN] The socket is already connected.
[EINVAL] The socket has already been shut down, has a listen active on it, or addrlen is a bad value.
[ETIMEDOUT] Connection establishment timed out without establishing a connection. Backlog may be full. (See listen(2).)
[ECONNREFUSED] The attempt to connect was forcefully rejected.
[ENETUNREACH] The network is not reachable from this host.
[EADDRINUSE] The address is already in use.
[EFAULT] The addr parameter is not a valid pointer.
[EINPROGRESS] The socket is non-blocking and the connection cannot be completed immediately. This is not a failure. Make the connect(2) call again a few seconds later.
[ENOBUFS] No buffer space is available. The connect has failed.
[EINTR] The connect was interrupted by delivery of a signal before the connect sequence was complete. The building of the connection still takes place, even though the user is not blocked on the connect call.
[EOPNOTSUPP] A connect attempt was made on a socket type which does not support this call.
DEPENDENCIES
Implemented on the Series 300 and 800 only.
AUTHOR
UCB (University of California at Berkeley)
SEE ALSO
accept(2), select(2), socket(2), getsockname(2), socket(7).
Hewlett-Packard Company — May 11, 2021