


connect(3)                                             connect(3)


NNAAMMEE
       connect - initiate a connection on a socket

SSYYNNOOPPSSIISS
       ##iinncclluuddee <<ssyyss//ssoocckkeett..hh>>

   AAFF__UUNNIIXX oonnllyy::
       ##iinncclluuddee <<ssyyss//uunn..hh>>

       iinntt ccoonnnneecctt((iinntt ss,, ssttrruucctt ssoocckkaaddddrr **aaddddrr,, ssiizzee__tt aaddddrrlleenn));;

DDEESSCCRRIIPPTTIIOONN
       The parameter _s is a socket descriptor.  _a_d_d_r is a pointer
       to  a  socket  address structure.  This structure contains
       the address of a remote socket to which a connection  will
       be  established.   _a_d_d_r_l_e_n  is  the  size  of this address
       structure.  Since the size of the socket address structure
       varies  among  socket address families, the correct socket
       address structure should be used with each address  family
       (for example, ssttrruucctt ssoocckkaaddddrr__uunn for AF_UNIX).  Typically,
       the _s_i_z_e_o_f function is used to pass this value (for  exam-
       ple, ssiizzeeooff((ssttrruucctt ssoocckkaaddddrr__uunn))).

       If the socket is of type SOCK_DGRAM, _c_o_n_n_e_c_t specifies the
       peer address to which messages are to  be  sent,  and  the
       call  returns  immediately.   Furthermore, this socket can
       only receive messages sent from this address.

       If the socket is of type SOCK_STREAM, _c_o_n_n_e_c_t attempts  to
       contact  the  remote  host  in  order to make a connection
       between the remote socket  (peer)  and  the  local  socket
       specified  by  _s.  The call normally blocks until the con-
       nection completes.  If non-blocking mode has been  enabled
       using the O_NDELAY _f_c_n_t_l flag and the connection cannot be
       completed  immediately,  _c_o_n_n_e_c_t  returns  an   error   as
       described below.  In these cases, _s_e_l_e_c_t(3) can be used on
       this socket to determine when the connection has completed
       by selecting it for writing.

       O_NDELAY is defined in <ffccnnttll..hh>.

       Generally,  stream  sockets  may successfully connect only
       once; datagram sockets may use _c_o_n_n_e_c_t multiple  times  to
       change  the  peer  address.   For datagram sockets, a side
       effect of attempting to connect to  some  invalid  address
       (see  DIAGNOSTICS  below)  is  that the peer address is no
       longer maintained by the system.  An example of an invalid
       address for a datagram socket is _a_d_d_r_l_e_n set to 0 and _a_d_d_r
       set to any value.  If you set the address  family  of  the
       destination  socket  to  AF_UNSPEC,  this  is  an  invalid
       address, too.

RREETTUURRNN VVAALLUUEE
       If the call is successful, 0 is returned.  If it fails, -1



                             MiNT-Net                           1





connect(3)                                             connect(3)


       is returned and an error code is stored in eerrrrnnoo.

DDIIAAGGNNOOSSTTIICCSS
       _c_o_n_n_e_c_t fails if:

       [EBADF]                  _s is not a valid file descriptor.

       [EAFNOSUPPORT]           Addresses   in   the    specified
                                address  family  cannot  be  used
                                with this socket.

                                For datagram  sockets,  the  peer
                                address  is  no longer maintained
                                by the system.

       [EALREADY]               Non-blocking I/O is enabled using
                                O_NDELAY  and  a previous connec-
                                tion attempt  has  not  yet  com-
                                pleted.

       [EISCONN]                The  socket is already connected.

       [EINVAL]                 The socket has already been  shut
                                down,  has  a _l_i_s_t_e_n active on it
                                or _a_d_d_r_l_e_n is a bad value.

                                For datagram sockets, if  _a_d_d_r_l_e_n
                                is  a bad value, the peer address
                                is no longer  maintained  by  the
                                system.   _s  is a file descriptor
                                for a file, not a socket.

       [ETIMEDOUT]              Connection  establishment   timed
                                out  without  establishing a con-
                                nection.   _b_a_c_k_l_o_g  may  be  full
                                (see _l_i_s_t_e_n(3)).

       [ECONNREFUSED]           The attempt to connect was force-
                                fully rejected.

       [EDESTADDRREQ]           _a_d_d_r is a NULL pointer.

       [EINPROGRESS]            Non-blocking I/O is enabled using
                                O_NDELAY  and the connection can-
                                not  be  completed   immediately.
                                This  is not a failure.  Make the
                                _c_o_n_n_e_c_t(3) call again a few  sec-
                                onds  later.  Alternatively, wait
                                for   completion    by    calling
                                _s_e_l_e_c_t(3), selecting for write.

       [EINTR]                  The  connect  was  interrupted by
                                delivery of a signal  before  the
                                connect  sequence  was  complete.



                             MiNT-Net                           2





connect(3)                                             connect(3)


                                The building  of  the  connection
                                still  takes  place,  even though
                                the user is not  blocked  on  the
                                _c_o_n_n_e_c_t call.

       [EOPNOTSUPP]             A  _c_o_n_n_e_c_t  attempt was made on a
                                socket type which does  not  sup-
                                port this call.

SSEEEE AALLSSOO
       accept(3), select(3), socket(3), getsockname(3).














































                             MiNT-Net                           3


