Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / MEM_Addr.cpp
blob518736b083ca3e518bc28c48de819d22db6f15e4
1 // Defines the Internet domain address family address format.
3 #include "ace/MEM_Addr.h"
5 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
7 #if !defined (__ACE_INLINE__)
8 #include "ace/MEM_Addr.inl"
9 #endif /* __ACE_INLINE__ */
11 #include "ace/Log_Category.h"
12 #include "ace/OS_NS_stdlib.h"
13 #include "ace/OS_NS_unistd.h"
14 #include "ace/os_include/os_netdb.h"
15 #if defined (ACE_HAS_ALLOC_HOOKS)
16 # include "ace/Malloc_Base.h"
17 #endif /* ACE_HAS_ALLOC_HOOKS */
19 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
21 ACE_ALLOC_HOOK_DEFINE(ACE_MEM_Addr)
23 /// Transform the current address into string format.
24 ACE_MEM_Addr::ACE_MEM_Addr ()
25 : ACE_Addr (AF_INET, sizeof (ACE_MEM_Addr))
27 // ACE_TRACE ("ACE_MEM_Addr::ACE_MEM_Addr");
28 this->initialize_local (0);
31 ACE_MEM_Addr::ACE_MEM_Addr (const ACE_MEM_Addr &sa)
32 : ACE_Addr (AF_INET, sizeof (ACE_MEM_Addr))
34 ACE_TRACE ("ACE_MEM_Addr::ACE_MEM_Addr");
35 this->external_.set (sa.external_);
36 this->internal_.set (sa.internal_);
39 ACE_MEM_Addr::ACE_MEM_Addr (const ACE_TCHAR port_number[])
40 : ACE_Addr (AF_INET, sizeof (ACE_MEM_Addr))
42 ACE_TRACE ("ACE_MEM_Addr::ACE_MEM_Addr");
43 u_short const pn = static_cast<u_short> (ACE_OS::strtoul (port_number, 0, 10));
44 this->initialize_local (pn);
47 ACE_MEM_Addr::ACE_MEM_Addr (u_short port_number)
48 : ACE_Addr (AF_INET, sizeof (ACE_MEM_Addr))
50 ACE_TRACE ("ACE_MEM_Addr::ACE_MEM_Addr");
51 this->initialize_local (port_number);
54 int
55 ACE_MEM_Addr::initialize_local (u_short port_number)
57 ACE_TCHAR name[MAXHOSTNAMELEN + 1];
58 if (ACE_OS::hostname (name, MAXHOSTNAMELEN+1) == -1)
59 return -1;
61 this->external_.set (port_number, name);
62 this->internal_.set (port_number, ACE_LOCALHOST);
63 return 0;
66 int
67 ACE_MEM_Addr::same_host (const ACE_INET_Addr &sap)
69 ACE_TRACE ("ACE_MEM_Addr::same_host");
71 // ACE_INET_Addr::operator== takes port number into account, so get
72 // the addresses without a port number and compare.
73 ACE_INET_Addr me (this->external_);
74 ACE_INET_Addr you (sap);
75 me.set_port_number (0);
76 you.set_port_number (0);
77 return me == you;
80 int
81 ACE_MEM_Addr::addr_to_string (ACE_TCHAR s[],
82 size_t size,
83 int ipaddr_format) const
85 ACE_TRACE ("ACE_MEM_Addr::addr_to_string");
87 return this->external_.addr_to_string (s, size, ipaddr_format);
90 // Transform the string into the current addressing format.
91 int
92 ACE_MEM_Addr::string_to_addr (const ACE_TCHAR s[])
94 ACE_TRACE ("ACE_MEM_Addr::string_to_addr");
96 u_short pn = static_cast<u_short> (ACE_OS::strtoul (s, 0, 10));
97 return this->set (pn);
100 /// Return the address.
101 void *
102 ACE_MEM_Addr::get_addr () const
104 ACE_TRACE ("ACE_MEM_Addr::get_addr");
105 return this->external_.get_addr ();
108 /// Set a pointer to the address.
109 void
110 ACE_MEM_Addr::set_addr (const void *addr, int len)
112 ACE_TRACE ("ACE_MEM_Addr::set_addr");
114 this->external_.set_addr (addr, len);
115 this->internal_.set_port_number (this->external_.get_port_number ());
119 ACE_MEM_Addr::get_host_name (ACE_TCHAR hostname[],
120 size_t len) const
122 ACE_TRACE ("ACE_MEM_Addr::get_host_name");
123 return this->external_.get_host_name (hostname, len);
126 /// Return the character representation of the hostname.
127 const char *
128 ACE_MEM_Addr::get_host_name () const
130 ACE_TRACE ("ACE_MEM_Addr::get_host_name");
131 return this->external_.get_host_name ();
134 u_long
135 ACE_MEM_Addr::hash () const
137 return this->external_.hash ();
140 void
141 ACE_MEM_Addr::dump () const
143 #if defined (ACE_HAS_DUMP)
144 ACE_TRACE ("ACE_MEM_Addr::dump");
146 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
147 this->external_.dump ();
148 this->internal_.dump ();
149 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
150 #endif /* ACE_HAS_DUMP */
153 ACE_END_VERSIONED_NAMESPACE_DECL
155 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */