ccoonnnneecctt() -- Sockets Function (libsocket)

Connect to a socket
#iinncclluuddee <ssyyss/ttyyppeess.hh>
#iinncclluuddee <ssyyss/ssoocckkeett.hh>
iinntt ccoonnnneecctt(_s_o_c_k_e_t, _n_a_m_e, _n_a_m_e_l_e_n)
iinntt _s_o_c_k_e_t, _n_a_m_e_l_e_n; ssttrruucctt ssoocckkaaddddrr *_n_a_m_e;

The function ccoonnnneecctt() establishes a connection for a socket.

_s_o_c_k_e_t  is a  file  identifier that  describes  a socket  possessed by  the
current process.  It  must have been returned by a  call to ssoocckkeett(). If it
is of  type SSOOCCKK_DDGGRRAAMM, ccoonnnneecctt() specifies the peer  with which the socket
is to be connected; this address is that to which datagrams are to be sent,
and the only address from which datagrams are to be received.  If, however,
it is  of type SSOOCCKK_SSTTRREEAAMM,  ccoonnnneecctt() attempts to connect  it with another
socket.  The other  socket is identified by _n_a_m_e, which  points to the full
path name of the file to  which the other socket is bound.  This connection
must have been established by a  call to function bbiinndd(). _n_a_m_e_l_e_n gives the
length, in bytes, of the file name to which _n_a_m_e points.

As a rule, a socket of type SSOOCCKK_SSTTRREEAAMM can successfully connect only once;
however, those of type SSOOCCKK_DDGGRRAAMM sockets can call ccoonnnneecctt() multiple times
to change their association.  Datagram sockets can dissolve the association
by connecting to an invalid address, such as a null address.

If the connection or binding succeeds, ccoonnnneecctt() returns zero.  If an error
occurs,  it  returns  -1 and  sets  eerrrrnnoo  to  an  appropriate value.   The
following lists the errors that can  occur, by the value to which ccoonnnneecctt()
sets eerrrrnnoo:

EEBBAADDFF
     _s_o_c_k_e_t is somehow invalid.

EENNOOTTSSOOCCKK
     _s_o_c_k_e_t references a file, not a socket.

_E_A_D_D_R_N_O_T_A_V_A_I_L
     The address is not available on this machine.

EEAAFFNNOOSSUUPPPPOORRTT
     Addresses in the specified address family cannot be used with _s_o_c_k_e_t.

EEIISSCCOONNNN
     _s_o_c_k_e_t is already connected to an address or socket.

EETTIIMMEEDDOOUUTT
     ccoonnnneecctt() timed out without establishing a connection.

EECCOONNNNRREEFFUUSSEEDD
     The attempt to connect was forcefully rejected.

EENNEETTUUNNRREEAACCHH
     The network is not reachable from this host.

EEAADDDDRRIINNUUSSEE
     The address is already in use.

EEFFAAUULLTT
     _n_a_m_e gives an illegal address.

EEIINNPPRROOGGRREESSSS
     _s_o_c_k_e_t  is  non-blocking   yet  the  connection  cannot  be  completed
     immediately.

EEAALLRREEAADDYY
     The socket  is non-blocking and  a previous call to  ccoonnnneecctt() has not
     yet been completed.

_E_x_a_m_p_l_e
For an example of this function, see the Lexicon entry for lliibbssoocckkeett.

_S_e_e _A_l_s_o
aacccceepptt(), ggeettssoocckknnaammee(), lliibbssoocckkeett, sseelleecctt(), ssoocckkeett()
