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
);
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)
61 this->external_
.set (port_number
, name
);
62 this->internal_
.set (port_number
, ACE_LOCALHOST
);
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);
81 ACE_MEM_Addr::addr_to_string (ACE_TCHAR s
[],
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.
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.
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.
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
[],
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.
128 ACE_MEM_Addr::get_host_name () const
130 ACE_TRACE ("ACE_MEM_Addr::get_host_name");
131 return this->external_
.get_host_name ();
135 ACE_MEM_Addr::hash () const
137 return this->external_
.hash ();
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 */