home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / OIP_SockAddress.cpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  3KB  |  122 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_SockAddress.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.  
  33. // $Header: W:/Projects/OCL/Source/rcs/OIP_SockAddress.cpp 1.50 1996/08/11 23:49:20 B.STEIN Release $
  34.  
  35. #define __OCL_SOURCE__
  36.  
  37. #define OINCL_OSTRING
  38. #define OINCL_BASE
  39.  
  40. #include <ocl.hpp>
  41. #include <OIP_SockAddress.hpp>
  42.  
  43.  
  44. OIP_SockAddress::OIP_SockAddress()
  45. {
  46.  memset(&data, 0, sizeof(data));
  47.  data.sin_family = AF_INET;
  48. }
  49.  
  50. OIP_SockAddress::~OIP_SockAddress()
  51.  {}
  52.  
  53. PSZ OIP_SockAddress::isOfType () const
  54. {
  55.  return("OIP_SockAddress");
  56. }
  57.  
  58. OIP_SockAddress::operator sockaddr_in()
  59. {
  60.  return(data);
  61. }
  62.  
  63. OIP_SockAddress::operator psockaddr_in()
  64. {
  65.  return(&data);
  66. }
  67.  
  68.  
  69. psockaddr_in OIP_SockAddress::Get_sockaddr_in()
  70. {
  71.  return(&data);
  72. }
  73.  
  74.  
  75. USHORT OIP_SockAddress::Setin_port(USHORT port)
  76. {
  77.  return(data.sin_port = htons(port));
  78. }
  79.  
  80. USHORT OIP_SockAddress::Getin_port()
  81. {
  82.  return(ntohs(data.sin_port));
  83. }
  84.  
  85.  
  86. ULONG OIP_SockAddress::Set_sin_addr(ULONG addr)
  87. {
  88.  return(data.sin_addr.S_un.s_addr = addr);
  89. }
  90.  
  91. ULONG OIP_SockAddress::Set_sin_addr(PSZ   target)
  92. {
  93.  return(data.sin_addr.S_un.s_addr = ::inet_addr(target));
  94. }
  95.  
  96. ULONG OIP_SockAddress::Get_sin_addr()
  97. {
  98.  return(data.sin_addr.S_un.s_addr);
  99. }
  100.  
  101. short OIP_SockAddress::Set_sin_family(short family)
  102. {
  103.  return(data.sin_family = family);
  104. }
  105.  
  106. short OIP_SockAddress::Get_sin_family()
  107. {
  108.  return(data.sin_family);
  109. }
  110.  
  111. void OIP_SockAddress::Get_inet_addr(PSZ   adress)
  112. {
  113.  sprintf(adress, "%u.%u.%u.%u",
  114.         (UINT)data.sin_addr.S_un.S_un_b.s_b1, (UINT)data.sin_addr.S_un.S_un_b.s_b2,
  115.         (UINT)data.sin_addr.S_un.S_un_b.s_b3, (UINT)data.sin_addr.S_un.S_un_b.s_b4);
  116.  
  117. }
  118.  
  119.  
  120.  
  121. // end of source
  122.