|
|
1.1 ! root 1: .TH CONNECT 2 "7 July 1983" ! 2: .UC 4 ! 3: .SH NAME ! 4: connect \- initiate a connection on a socket ! 5: .SH SYNOPSIS ! 6: .nf ! 7: .ft B ! 8: #include <sys/types.h> ! 9: #include <sys/socket.h> ! 10: #include <sys/un.h> /* for Unix domain only */ ! 11: #include <netinet/in.h> /* for Internet domain only */ ! 12: .PP ! 13: .ft B ! 14: connect(s, name, namelen) ! 15: int s; ! 16: struct sockaddr *name; ! 17: int namelen; ! 18: .fi ! 19: .SH DESCRIPTION ! 20: The parameter ! 21: .I s ! 22: is a socket. ! 23: If it is of type SOCK_DGRAM, ! 24: then this call permanently specifies the peer to which ! 25: datagrams are to be sent; ! 26: if it is of type SOCK_STREAM, ! 27: then this call attempts to make a connection to ! 28: another socket. ! 29: The other socket is specified by ! 30: .I name ! 31: which is an address in the communications space of the socket. ! 32: Each communications space interprets the ! 33: .I name ! 34: parameter in its own way. ! 35: .SH "RETURN VALUE ! 36: If the connection or binding succeeds, then 0 is returned. ! 37: Otherwise a \-1 is returned, and a more specific error ! 38: code is stored in \fIerrno\fP. ! 39: .SH "ERRORS ! 40: The call fails if: ! 41: .TP 20 ! 42: [EBADF] ! 43: .I S ! 44: is not a valid descriptor. ! 45: .TP 20 ! 46: [ENOTSOCK] ! 47: .I S ! 48: is a descriptor for a file, not a socket. ! 49: .TP 20 ! 50: [EADDRNOTAVAIL] ! 51: The specified address is not available on this machine. ! 52: .TP 20 ! 53: [EAFNOSUPPORT] ! 54: Addresses in the specified address family cannot be used with this socket. ! 55: .TP 20 ! 56: [EISCONN] ! 57: The socket is already connected. ! 58: .TP 20 ! 59: [ETIMEDOUT] ! 60: Connection establishment timed out without establishing a connection. ! 61: .TP 20 ! 62: [ECONNREFUSED] ! 63: The attempt to connect was forcefully rejected. ! 64: .TP 20 ! 65: [ENETUNREACH] ! 66: The network isn't reachable from this host. ! 67: .TP 20 ! 68: [EADDRINUSE] ! 69: The address is already in use. ! 70: .TP 20 ! 71: [EFAULT] ! 72: The \fIname\fP parameter specifies an area outside ! 73: the process address space. ! 74: .TP 20 ! 75: [EWOULDBLOCK] ! 76: The socket is non-blocking and the ! 77: and the connection cannot ! 78: be completed immediately. ! 79: It is possible to ! 80: .IR select (2) ! 81: the socket while it is connecting by selecting it for writing. ! 82: .SH SEE ALSO ! 83: accept(2), select(2), socket(2), getsockname(2). ! 84: See also bind(2) for address formats in different communication domains.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.