Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

MEM_Addr.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // $Id: MEM_Addr.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:21 chad Exp $
00003 
00004 // Defines the Internet domain address family address format.
00005 
00006 #include "ace/MEM_Addr.h"
00007 #include "ace/Log_Msg.h"
00008 
00009 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
00010 
00011 #if !defined (__ACE_INLINE__)
00012 #include "ace/MEM_Addr.i"
00013 #endif /* __ACE_INLINE__ */
00014 
00015 ACE_RCSID(ace, MEM_Addr, "$Id: MEM_Addr.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:21 chad Exp $")
00016 
00017 ACE_ALLOC_HOOK_DEFINE(ACE_MEM_Addr)
00018 
00019 // Transform the current address into string format.
00020 
00021 ACE_MEM_Addr::ACE_MEM_Addr (void)
00022   : ACE_Addr (AF_INET, sizeof (ACE_MEM_Addr))
00023 {
00024   // ACE_TRACE ("ACE_MEM_Addr::ACE_MEM_Addr");
00025   this->initialize_local (0);
00026 }
00027 
00028 ACE_MEM_Addr::ACE_MEM_Addr (const ACE_MEM_Addr &sa)
00029   : ACE_Addr (AF_INET, sizeof (ACE_MEM_Addr))
00030 {
00031   ACE_TRACE ("ACE_MEM_Addr::ACE_MEM_Addr");
00032   this->external_.set (sa.external_);
00033   this->internal_.set (sa.internal_);
00034 }
00035 
00036 ACE_MEM_Addr::ACE_MEM_Addr (const ACE_TCHAR port_number[])
00037   : ACE_Addr (AF_INET, sizeof (ACE_MEM_Addr))
00038 {
00039   ACE_TRACE ("ACE_MEM_Addr::ACE_MEM_Addr");
00040   u_short pn
00041     = ACE_static_cast (u_short,
00042                        ACE_OS::strtoul (port_number,
00043                                         0,
00044                                         10));
00045   this->initialize_local (pn);
00046 }
00047 
00048 ACE_MEM_Addr::ACE_MEM_Addr (u_short port_number)
00049   : ACE_Addr (AF_INET, sizeof (ACE_MEM_Addr))
00050 {
00051   ACE_TRACE ("ACE_MEM_Addr::ACE_MEM_Addr");
00052   this->initialize_local (port_number);
00053 }
00054 
00055 int
00056 ACE_MEM_Addr::initialize_local (u_short port_number)
00057 {
00058   ACE_TCHAR name[MAXHOSTNAMELEN + 1];
00059   if (ACE_OS::hostname (name, MAXHOSTNAMELEN+1) == -1)
00060     return -1;
00061 
00062   this->external_.set (port_number, name);
00063   this->internal_.set (port_number, ACE_LIB_TEXT ("localhost"));
00064   return 0;
00065 }
00066 
00067 int
00068 ACE_MEM_Addr::same_host (const ACE_INET_Addr &sap)
00069 {
00070   ACE_TRACE ("ACE_MEM_Addr::same_host");
00071 
00072   ACE_UINT32 me = this->external_.get_ip_address ();
00073   ACE_UINT32 you = sap.get_ip_address ();
00074 
00075   return me == you;
00076 }
00077 
00078 int
00079 ACE_MEM_Addr::addr_to_string (ACE_TCHAR s[],
00080                               size_t size,
00081                               int ipaddr_format) const
00082 {
00083   ACE_TRACE ("ACE_MEM_Addr::addr_to_string");
00084 
00085   return this->external_.addr_to_string (s, size, ipaddr_format);
00086 }
00087 
00088 // Transform the string into the current addressing format.
00089 
00090 int
00091 ACE_MEM_Addr::string_to_addr (const ACE_TCHAR s[])
00092 {
00093   ACE_TRACE ("ACE_MEM_Addr::string_to_addr");
00094 
00095   u_short pn
00096     = ACE_static_cast (u_short,
00097                        ACE_OS::strtoul (s,
00098                                         0,
00099                                         10));
00100   return this->set (pn);
00101 }
00102 
00103 // Return the address.
00104 
00105 void *
00106 ACE_MEM_Addr::get_addr (void) const
00107 {
00108   ACE_TRACE ("ACE_MEM_Addr::get_addr");
00109   return this->external_.get_addr ();
00110 }
00111 
00112 // Set a pointer to the address.
00113 void
00114 ACE_MEM_Addr::set_addr (void *addr, int len)
00115 {
00116   ACE_TRACE ("ACE_MEM_Addr::set_addr");
00117 
00118   this->external_.set_addr (addr, len);
00119   this->internal_.set_port_number (this->external_.get_port_number ());
00120 }
00121 
00122 int
00123 ACE_MEM_Addr::get_host_name (ACE_TCHAR hostname[],
00124                               size_t len) const
00125 {
00126   ACE_TRACE ("ACE_MEM_Addr::get_host_name");
00127   return this->external_.get_host_name (hostname, len);
00128 }
00129 
00130 // Return the character representation of the hostname.
00131 
00132 const char *
00133 ACE_MEM_Addr::get_host_name (void) const
00134 {
00135   ACE_TRACE ("ACE_MEM_Addr::get_host_name");
00136   return this->external_.get_host_name ();
00137 }
00138 
00139 void
00140 ACE_MEM_Addr::dump (void) const
00141 {
00142   ACE_TRACE ("ACE_MEM_Addr::dump");
00143 
00144   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00145   this->external_.dump ();
00146   this->internal_.dump ();
00147   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00148 }
00149 
00150 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */

Generated on Mon Jun 16 11:20:16 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002