#include <sys/types.h>
#include <sys/socket.h>
int connect(int socket_descriptor,
struct sockaddr *destination_address,
int address_length)
|
The connect() function is used to establish a connection on a connection-oriented socket or establish the destination address on a connectionless socket.
Parameters
struct sockaddr {
u_short sa_family;
char sa_data[14];
};
The sa_family field identifies the address family to which the address belongs, and sa_data is the address whose format is dependent on the address family.
Return Value
connect() returns an integer. Possible values are:
Error Conditions
When a connect() fails, errno can be set to one of the following. For additional debugging information, see Debugging IP over SNA Configurations and Appendix E, IPX Problem Analysis in the Internetwork Packet Exchange (IPX) Support book.
This error code indicates one of the following:
This error code indicates one of the following:
Note: Sockets with an address family of AF_NS can have non-unique associations of local and remote addresses. This is because the underlying transport protocol utilizes a connection identifier number which is unique for each socket, regardless of the address associated with the socket.
This error code indicates one of the following:
The address family specified in the address structure pointed to by destination_address parameter cannot be used with the socket pointed to by the socket_descriptor parameter.
A previous connect() function had already been issued for the socket pointed to by the socket_descriptor parameter, and has yet to be completed. This error code is returned only on sockets that use a connection-oriented transport service.
This error occurs when there is no application that is bound to the address specified by the destination_address parameter.
Note: For sockets with address family AF_NS, this error condition is not reported if the address specified by destination_address is not a loopback address.
The system detected an address which was not valid while attempting to access the destination_address parameter.
This error code is returned on sockets that use the AF_INET and AF_TELEPHONY address families.
For address family AF_TELEPHONY sockets, this error indicates that the default connection list entry was not available.
The socket_descriptor parameter points to a socket that is marked as nonblocking and the connection could not be completed immediately. This error code is returned only on sockets that use a connection-oriented transport service.
This error code indicates one of the following:
Note: For sockets that have an address family of AF_UNIX or AF_NS if a connect() fails, a subsequent connect() is allowed, even if the transport service being used is connection-oriented.
This error code is returned only on sockets that use a connection-oriented transport service.
This error code is only returned on sockets that use the AF_UNIX address family.
This error code is only returned on sockets that use the AF_UNIX address family.
This error code indicates the following:
This error code is only returned on sockets that use the AF_UNIX address family.
This error code is only returned on sockets that use the AF_UNIX address family.
This error code is only returned on sockets that use the AF_UNIX address family.
connect() is not allowed on a passive socket (a socket for which a listen() has been done).
This error code is only returned on sockets that use the AF_UNIX address family.
This error code is returned when connection establishment times out. No connection is established. A possible cause may be that the partner application is bound to the address specified by the destination_address parameter, but the partner application has not yet issued a listen().
Note: For sockets with an address family of AF_NS, this error may also be reported when there is no application bound to the address specified by the destination_address parameter.
Error Messages
Usage Notes
Note: Issuing connect() on sockets of type SOCK_DGRAM and SOCK_RAW is not recommended because of dynamic route reassignment (picking a new route when a route that was previously used is no longer available). When this reassignment occurs, the next packet from the partner program can be received from a different IP address than the address your application specified on the connect(). This results in the data being discarded.
Related Information
| Top | Sockets APIs | APIs by category |
| [Information Center Home Page | Feedback ] | [Legal | AS/400 Glossary] |