TCP/IP Programming Manual
socket
input value; specifies the socket number for the socket, as returned by the call to socket or
socket_nw.
address_ptr
input value; points to the address and port number (based on the structure sockaddr_in,
sockaddr_in6, sockaddr_storage) of the remote socket to which a connection is to be
established.
address_len
input value; should be a value indicating the size in bytes of the remote address and port
number pointed to by address_ptr.
tag
input value; the tag parameter to be used for the nowait operation initiated by connect_nw.
Errors
If an error occurs, the external variable errno is set to one of the following values:
There is already an outstanding call on the socket.EALREADY
The specified socket was already connected.EISCONN
The connection timed out without being established.ETIMEDOUT
The remote host rejected the connection.ECONNREFUSED
The network (of the remote host) was unreachable.ENETUNREACH
One of the arguments to this call was invalid.EINVAL
Usage Guidelines
• Use connect on a socket created for waited operations, or connect_nw on a socket created
for nowait operations. The operation initiated by connect_nw must be completed with a call
to the AWAITIOX procedure.
• For more information on checking errors, see Nowait Call Errors (page 86).
• For more information about struct sockaddr *, struct sockaddr_in6 and
sockaddr_storage, see Chapter 3 (page 62). Also, see getaddrinfo (page 107) and addrinfo
(page 64).
• Declare the address_ptr variable as struct sockaddr_in6 * for IPv6 use or as
struct sockaddr_storage * for protocol-independent use. In C, when you make the
call, cast the variable to sockaddr *. (See the “Examples” (page 103).)
NOTE: Using CIP, when trying to connect to a remote IPv6 link-local address might fail with error
EINVAL. This error is displayed when:
• The socket is not bound to the IPv6 link-local address on the local interface, or
• The scope ID (sin6_scope_id member in struct sockaddr_in6) is not specified.
Examples
INET: The following programming example calls the connect routine that connects the socket fd
to a remote socket. The remote structure contains the address and port of the remote socket:
#include <socket.h>
#include <in.h>
#include <netdb.h>
...
struct sockaddr_in remote;
....
connect, connect_nw 103