p If a .Fn connect call is interrupted by a signal, it will return with errno set to .Er EINTR and the connection attempt will proceed as if the socket was non-blocking. Subsequent calls to .Fn connect will set errno to .Er EALREADY . .Sh RETURN VALUES If the connection or binding succeeds, 0 is returned. Otherwise a -1 is returned, and a more specific error code is stored in .Va errno . .Sh ERRORS The .Fn connect call fails if: l -tag -width Er t Bq Er EBADF .Fa s is not a valid descriptor. t Bq Er ENOTSOCK .Fa s is a descriptor for a file, not a socket. t Bq Er EINVAL The socket address length passed was outside the allowable range. t Bq Er EADDRNOTAVAIL The specified address is not available on this machine. t Bq Er EAFNOSUPPORT Addresses in the specified address family cannot be used with this socket. t Bq Er EISCONN The socket is already connected. t Bq Er ETIMEDOUT Connection establishment timed out without establishing a connection. t Bq Er ECONNREFUSED The attempt to connect was forcefully rejected. t Bq Er ENETUNREACH The network isn't reachable from this host. t Bq Er EADDRINUSE The address is already in use. t Bq Er EFAULT The .Fa name parameter specifies an area outside the process address space. t Bq Er EINPROGRESS The socket is non-blocking and the connection cannot be completed immediately. It is possible to .Xr select 2 or .Xr poll 2 for completion by selecting or polling the socket for writing. The success or failure of the connect operation may be determined by using .Xr getsockopt 2 to read the socket error status with the .Dv SO_ERROR option at the .Dv SOL_SOCKET level. The returned socket error status is zero on success, or one of the error codes listed here on failure. t Bq Er EALREADY Either the socket is non-blocking mode or a previous call to .Fn connect was interrupted by a signal, and the connection attempt has not yet been completed. t Bq Er EINTR The connection attempt was interrupted by a signal. .El
p The following errors are specific to connecting names in the x domain. These errors may not apply in future versions of the x IPC domain. l -tag -width Er t Bq Er ENOTDIR A component of the path prefix is not a directory. t Bq Er ENAMETOOLONG A component of a pathname exceeded rq Dv NAME_MAX characters, or an entire path name exceeded rq Dv PATH_MAX characters. t Bq Er ENOENT The named socket does not exist. t Bq Er EACCES Search permission is denied for a component of the path prefix, or write access to the named socket is denied. t Bq Er ELOOP Too many symbolic links were encountered in translating the pathname. .El .Sh SEE ALSO .Xr accept 2 , .Xr getsockname 2 , .Xr getsockopt 2 , .Xr poll 2 , .Xr select 2 , .Xr socket 2 .Sh HISTORY The .Fn connect function call appeared in x 4.2 .