connect(SSC) 6 January 1993 connect(SSC) Name connect - initiate a connection on a socket Syntax #include <sys/types.h> #include <sys/socket.h> int connect (s, name, namelen) int s; struct sockaddr *name; int namelen; Description connect initiates a connection on a socket. The parameter s is a socket. If it is of type SOCKDGRAM, then this call permanently specifies the peer to which datagrams are to be sent; if it is of type SOCKSTREAM, then this call attempts to make a connection to another socket. The other socket is specified by name; namelen is the length of name, which is an address in the address family of the socket. Each address family interprets the name parameter in its own way. Return value A return value of zero indicates that the call succeeded. A return value of -1 indicates that an error occurred, and in this case an error code is stored in the global variable errno. Errors The call fails if: [EBADF] The argument s is not a valid descriptor. [ENOTSOCK] The argument s is a descriptor for a file, not a socket. [EADDRNOTAVAIL] The specified address is not available on this ma- chine. [EAFNOSUPPORT] Addresses in the specified address family cannot be used with this socket. [EISCONN] The socket is already connected. [ETIMEDOUT] Connection establishment timed out without establish- ing a connection. [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 name parameter specifies an area outside the pro- cess address space. See also Intro(SSC), accept(SSC), getsockname(SSC), socket(SSC) and intro(ADMP).