home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / OIP_Address.cpp < prev    next >
C/C++ Source or Header  |  1997-02-19  |  3KB  |  127 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_Address.cpp
  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. // $Header: W:/Projects/OCL/Source/rcs/OIP_Address.cpp 1.50 1996/08/11 23:49:18 B.STEIN Release $
  33.  
  34. #define __OCL_SOURCE__
  35.  
  36. #define OINCL_OSTRING
  37. #define OINCL_BASE
  38.  
  39. #include <ocl.hpp>
  40. #include <OIP_Address.hpp>
  41.  
  42.  
  43.  
  44. OIP_Address::OIP_Address()
  45. {
  46.  addr_data.S_un.s_addr = 0;
  47. }
  48.  
  49.  
  50. OIP_Address::OIP_Address(UCHAR i1, UCHAR i2, UCHAR i3, UCHAR i4)
  51. {
  52.  Set_s_addr(i1, i2, i3, i4);
  53. }
  54.  
  55.  
  56. OIP_Address::OIP_Address(ULONG addr)
  57. {
  58.  addr_data.S_un.s_addr = lswap(addr);
  59. }
  60.  
  61.  
  62. OIP_Address::~OIP_Address()
  63. {}
  64.  
  65.  
  66. PSZ OIP_Address::isOfType () const
  67. {
  68.  return("OIP_Address");
  69. }
  70.  
  71.  
  72. ULONG OIP_Address::Set_s_addr(ULONG addr)
  73. {
  74.  return(addr_data.S_un.s_addr = addr);
  75. }
  76.  
  77.  
  78. ULONG OIP_Address::Get_s_addr()
  79. {
  80.  return(addr_data.S_un.s_addr);
  81. }
  82.  
  83.  
  84. OIP_Address::operator ULONG()
  85. {
  86.  return(addr_data.S_un.s_addr);
  87. }
  88.  
  89.  
  90.  
  91. OIP_Address::operator = (ULONG addr)
  92. {
  93.  return(addr_data.S_un.s_addr = addr);
  94. }
  95.  
  96.  
  97. void OIP_Address::Set_s_addr(UCHAR i1, UCHAR i2, UCHAR i3, UCHAR i4)
  98. {
  99.  addr_data.S_un.s_addr = lswap((i1 << 24) | (i2 << 16) | (i3 << 8) | i4);
  100. }
  101.  
  102.  
  103.  
  104. int OIP_Address::Set_s_addr(PSZ addrtext)
  105. {
  106.  UCHAR i1, i2, i3, i4, i;
  107.  int ok = -1;
  108.  
  109.  if (sscanf(addrtext, "%u.%u.%u.%u%c", &i1, &i2, &i3, &i4, &i) == 4)
  110.    {
  111.     Set_s_addr(i1, i2, i3, i4);
  112.     ok = 0;
  113.    }
  114.  return ok;
  115. }
  116.  
  117.  
  118. void OIP_Address::Get_inet_addr(PSZ adress)
  119. {
  120.  sprintf(adress, "%u.%u.%u.%u",
  121.         (UINT)addr_data.S_un.S_un_b.s_b1, (UINT)addr_data.S_un.S_un_b.s_b2,
  122.         (UINT)addr_data.S_un.S_un_b.s_b3, (UINT)addr_data.S_un.S_un_b.s_b4);
  123. }
  124.  
  125.  
  126. // end of source
  127.