NetSock_Conn

Connect a local socket to a remote socket address. If the local socket was not previously bound to a local address and port, the socket is bound to the default interface’s default address and a random port number. When successful, a connected socket has access to both local and remote socket addresses.

Although both UDP and TCP sockets may both connect to remote servers or hosts, UDP and TCP connections are inherently different:

For TCP sockets, NetSock_Conn()/connect() returns successfully only after completing the three-way TCP handshake with the remote TCP host. Success implies the existence of a dedicated connection to the remote socket similar to a telephone connection. This dedicated connection is maintained for the life of the connection until one or both sides close the connection.

For UDP sockets, NetSock_Conn()/connect() merely saves the remote socket’s address for the local socket for convenience. All UDP datagrams from the socket will be transmitted to the remote socket. This pseudo-connection is not permanent and may be re-configured at any time.

Files

net_sock.h/net_sock.c
net_bsd.h/net_bsd.c

Prototypes

NET_SOCK_RTN_CODE  NetSock_Conn(NET_SOCK_ID        sock_id,
                                NET_SOCK_ADDR     *p_addr_remote,
                                NET_SOCK_ADDR_LEN  addr_len,
                                NET_ERR           *p_err);

int                connect     (       int         sock_id,
                                struct sockaddr   *paddr_remote,
                                       socklen_t   addr_len);

Arguments

sock_id

This is the socket ID returned by NetSock_Open()/socket() when the socket was created.

p_addr_remote

Pointer to a socket address structure (see section 8-2 “Socket Interface”) which contains the remote socket address to connect the socket to.

addr_len

Size of the socket address structure which must be passed the size of the socket address structure [e.g., sizeof(NET_SOCK_ADDR_IP)].

p_err

Pointer to variable that will receive the return error code from this function:

NET_SOCK_ERR_NONE
NET_SOCK_ERR_NOT_USED
NET_SOCK_ERR_CLOSED
NET_SOCK_ERR_INVALID_SOCK
NET_SOCK_ERR_INVALID_FAMILY
NET_SOCK_ERR_INVALID_PROTOCOL
NET_SOCK_ERR_INVALID_TYPE
NET_SOCK_ERR_INVALID_STATE
NET_SOCK_ERR_INVALID_OP
NET_SOCK_ERR_INVALID_ADDR
NET_SOCK_ERR_INVALID_ADDR_LEN
NET_SOCK_ERR_ADDR_IN_USE
NET_SOCK_ERR_PORT_NBR_NONE_AVAIL
NET_SOCK_ERR_CONN_SIGNAL_TIMEOUT
NET_SOCK_ERR_CONN_IN_USE
NET_SOCK_ERR_CONN_FAIL
NET_SOCK_ERR_FAULT
NET_IF_ERR_INVALID_IF
NET_ERR_FAULT_NULL_PTR
NET_CONN_ERR_NOT_USED
NET_CONN_ERR_NONE_AVAIL
NET_CONN_ERR_INVALID_CONN
NET_CONN_ERR_INVALID_FAMILY
NET_CONN_ERR_INVALID_TYPE
NET_CONN_ERR_INVALID_PROTOCOL_IX
NET_CONN_ERR_INVALID_ADDR_LEN
NET_CONN_ERR_ADDR_NOT_USED
NET_CONN_ERR_ADDR_IN_USE
NET_INIT_ERR_NOT_COMPLETED
NET_ERR_FAULT_LOCK_ACQUIRE

Returned Value

NET_SOCK_BSD_ERR_NONE/0, if successful;

NET_SOCK_BSD_ERR_CONN/-1, otherwise.

Required Configuration

None.

Notes / Warnings

See section Network Sockets Concepts for socket address structure formats.