gtpc1m3nTransmission Control Protocol/Internet Protocol

connect -- Request a Connection to a Remote Host

The connect function requests a connection to a remote host.

Format

#include  <socket.h>
int       connect(int s,
                  struct sockaddr *name,
                  int namelen);

s
The socket descriptor. The s parameter is the socket used to originate the connection request.

name
Pointer to a sockaddr structure that contains the address of the socket to which a connection will be attempted.

namelen
Size, in bytes, of the sockaddr structure pointed to by name.

Normal Return

Return code 0 indicates that the function was successful.

Error Return

A return code equal to -1 indicates an error. You can get the specific error code by calling sock_errno. See Appendix C, Socket Error Return Codes for more information about socket errors.

Note:
Unless otherwise stated in the description, the following error codes can be returned for either TCP/IP offload support or TCP/IP native stack support.

Value
Description

SOCADDRNOTAVAIL
The calling host cannot reach the specified destination.

SOCAFNOSUPPORT
The address family is not supported.

SOCALREADY
Socket s is marked nonblocking and a previous connection attempt has not completed.

SOCCONNREFUSED
The connection request was rejected by the destination host.

SOCFAULT
Using name and namelen would result in an attempt to copy the address into a protected address space. This error code is returned only for TCP/IP offload support.

SOCINPROGRESS
Socket s is marked nonblocking, and the connection cannot be completed immediately. The SOCINPROGRESS value does not indicate an error condition.

SOCISCONN
Socket s is already connected.

SOCNETUNREACH
You cannot get to the network from this host. This error code is returned only for TCP/IP offload support.

SOCTIMEDOUT
A timeout occurred before the connection was made. This error code is returned only for TCP/IP native stack support.

SOCNOBUFS
There is not enough buffer space to start a new connection.

SOCNOTSOCK
The s parameter is not a valid socket descriptor.

SOCOPNOTSUP
The operation is not supported on the socket. This error code is returned only for TCP/IP offload support.

SOCIPNOTFOUND
The TPF system could not locate the IP table header. This error code is returned only for TCP/IP offload support.

E1052STATE
The socket was closed because the system was in or cycling down to 1052 state.

EINACT
All offload devices associated with the socket descriptor have been disconnected. The socket is closed. This error code is returned only for TCP/IP offload support.

EINACTWS
An offload device associated with the socket descriptor has been disconnected. The socket is still available. This error code is returned only for TCP/IP offload support.

ESYSTEMERROR
A system error has occurred and closed the socket.

EIBMIUCVERR
An error occurred while the function call was being sent to the offload device. This error code is returned only for TCP/IP offload support.

SOCINVAL
The namelen parameter is not a valid length. This error code is returned only for TCP/IP native stack support.

Programming Considerations

Examples

The following example connects to a server application that has IP address 129.5.24.1 and port number 5001.

#include <socket.h>

·
·
·
int rc; int client_sock; struct sockaddr_in server_addr;
·
·
·
memset(&server_addr, 0,sizeof(server_addr)); server_addr.sin_family = AF_INET; server_addr.sin_port = 5001; server_addr.sin_addr.s_addr = inet_addr("129.5.24.1"); rc = connect(client_sock, (struct sockaddr *) &server_addr, sizeof(server_addr));

Related Information