home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / oclsrc15.zip / OCL / Include / OIP_Socket.hpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  5KB  |  173 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1996
  3. // (c) 1982, 1985, 1986 Regents of the University of California.
  4. // (c) Raoul Gema 1996
  5. // All Rights Reserved
  6. // OIP_Socket.hpp
  7.  
  8. /*
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  15.  *    endorse or promote products derived from this software
  16.  *    without specific prior written permission.
  17.  * 3. See OCL.INF for a detailed copyright notice.
  18.  *
  19.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  20.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  23.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29.  * SUCH DAMAGE.
  30.  */
  31.  
  32.  
  33. // $Header: W:/Projects/OCL/Include/rcs/OIP_Socket.hpp 1.50 1996/08/11 23:47:17 B.STEIN Release $
  34.  
  35.  
  36. #ifndef OIP_SOCKET_INCLUDED
  37.    #define OIP_SOCKET_INCLUDED
  38.  
  39. #ifndef OEXCEPTION_INCLUDED
  40.    #include <OException.hpp>
  41. #endif
  42.  
  43. #ifndef OIP_SOCKADDRESS_INCLUDED
  44.    #include <OIP_SockAddress.hpp>
  45. #endif
  46.  
  47. #ifndef OIP_HOST_INCLUDED
  48.    #include <OIP_Host.hpp>
  49. #endif
  50.  
  51.  
  52. typedef class OIP_Socket* pOIP_Socket;
  53.  
  54.  
  55. class __CPP_EXPORT__ OIP_Socket
  56.   : public OCLObject
  57. {
  58.  protected:
  59.      OIP_SockAddress  sockadd;
  60.      OIP_Host         *phost;
  61.      int              s;
  62.  
  63.  public:
  64.  
  65.     class OIP_SocketException
  66.       : public OException
  67.       {
  68.        public:
  69.          enum  excepttyp
  70.           {
  71.            esocket        = 10,
  72.            elisten        = 11,
  73.            ebind          = 12,
  74.            esend          = 13,
  75.            erecv          = 14,
  76.            econnect       = 15,
  77.            egethostbyname = 16,
  78.            egethostbyaddr = 17
  79.           };
  80.  
  81.          excepttyp etyp;
  82.          int       value;
  83.  
  84.          OIP_SocketException     (excepttyp typ,
  85.                                   int errorvalue);
  86.  
  87.          virtual 
  88.             ~OIP_SocketException ();
  89.  
  90.          virtual
  91.             PSZ isOfType         () const;
  92.  
  93.          virtual
  94.             void viewError       ();
  95.  
  96.       };
  97.  
  98.    OIP_Socket        ();
  99.  
  100.    OIP_Socket        (phostent p);
  101.  
  102.    virtual
  103.      ~OIP_Socket     ();
  104.  
  105.    virtual
  106.      PSZ isOfType    () const;
  107.  
  108.    virtual int
  109.      sysinit         (USHORT version),
  110.      sysfree         ();
  111.  
  112.    int
  113.      Set_socket      (int sock),
  114.      Get_socket      (),
  115.      close           (),
  116.      Gethostname     (PSZ hostname, UINT size);
  117.  
  118.  
  119.    pOIP_Host
  120.      Gethostbyaddr   (PSZ hostaddress, int type = PF_INET),
  121.      Gethostbyname   (PSZ hostname),
  122.      Get_phost       (),
  123.      Sethostent      (phostent phost);
  124.  
  125.    pservent
  126.      Getservbyname   (PSZ, PSZ);
  127.  
  128.    USHORT
  129.      Getin_port      ();
  130.  
  131.    void
  132.      Setin_port      (USHORT port);
  133.  
  134.    ULONG
  135.      Set_sin_addr    (),
  136.      Set_sin_addr    (ULONG addr),
  137.      Set_sin_addr    (PSZ target),
  138.      Get_sin_addr    (),
  139.      Getaddr_list    (UINT index = 0);
  140.  
  141.    BOOL
  142.      Set_address     (USHORT port, PSZ target);
  143.  
  144.    short
  145.      Set_sin_family  (short family = AF_INET),
  146.      Get_sin_family  ();
  147.  
  148.    int
  149.      socket          (int net = AF_INET, int typ = SOCK_STREAM, int x = 0),
  150.      send            (PSZ buffer, int size, int options = 0),
  151.      recv            (PSZ buffer, int size, int options = 0),
  152.      GetErrorCode    (),
  153.      setsockopt      (int, int, PSZ, int),
  154.      recvfrom        (PSZ, int, int, psockaddr, PINT),
  155.      sendto          (PSZ, int, int, psockaddr, int);
  156.  
  157.    void
  158.      Get_inet_addr   (PSZ adress);
  159.  
  160.    psockaddr
  161.      Get_sockaddr    ();
  162.  
  163. // operators
  164.  
  165.    operator =                (int handle);
  166.    operator int              ();
  167.    operator OIP_SockAddress  ();
  168.    operator pOIP_SockAddress ();
  169. };
  170.  
  171. #endif    // OIP_SOCKET
  172.  
  173.