Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "ace/OS_NS_string.h"
00007 #include "ace/Global_Macros.h"
00008 #include "ace/OS_NS_arpa_inet.h"
00009
00010 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00011
00012 ACE_INLINE void
00013 ACE_INET_Addr::reset (void)
00014 {
00015 ACE_OS::memset (&this->inet_addr_, 0, sizeof (this->inet_addr_));
00016 if (this->get_type() == AF_INET)
00017 {
00018 #ifdef ACE_HAS_SOCKADDR_IN_SIN_LEN
00019 this->inet_addr_.in4_.sin_len = sizeof (this->inet_addr_.in4_);
00020 #endif
00021 this->inet_addr_.in4_.sin_family = AF_INET;
00022 }
00023 #if defined (ACE_HAS_IPV6)
00024 else if (this->get_type() == AF_INET6)
00025 {
00026 #ifdef ACE_HAS_SOCKADDR_IN6_SIN6_LEN
00027 this->inet_addr_.in6_.sin6_len = sizeof (this->inet_addr_.in6_);
00028 #endif
00029 this->inet_addr_.in6_.sin6_family = AF_INET6;
00030 }
00031 #endif
00032 }
00033
00034 ACE_INLINE int
00035 ACE_INET_Addr::determine_type (void) const
00036 {
00037 #if defined (ACE_HAS_IPV6)
00038 # if defined (ACE_USES_IPV4_IPV6_MIGRATION)
00039 return ACE::ipv6_enabled () ? AF_INET6 : AF_INET;
00040 # else
00041 return AF_INET6;
00042 # endif
00043 #else
00044 return AF_INET;
00045 #endif
00046 }
00047
00048 ACE_INLINE void *
00049 ACE_INET_Addr::ip_addr_pointer (void) const
00050 {
00051 #if defined (ACE_HAS_IPV6)
00052 if (this->get_type () == PF_INET)
00053 return (void*)&this->inet_addr_.in4_.sin_addr;
00054 else
00055 return (void*)&this->inet_addr_.in6_.sin6_addr;
00056 #else
00057 return (void*)&this->inet_addr_.in4_.sin_addr;
00058 #endif
00059 }
00060
00061 ACE_INLINE int
00062 ACE_INET_Addr::ip_addr_size (void) const
00063 {
00064
00065
00066
00067
00068 #if defined (ACE_HAS_IPV6)
00069 if (this->get_type () == PF_INET)
00070 return static_cast<int> (sizeof this->inet_addr_.in4_.sin_addr);
00071 else
00072 return static_cast<int> (sizeof this->inet_addr_.in6_.sin6_addr);
00073 #else
00074
00075
00076
00077 # if !defined(_UNICOS)
00078 return static_cast<int> (sizeof this->inet_addr_.in4_.sin_addr.s_addr);
00079 # else
00080 return static_cast<int> (sizeof this->inet_addr_.in4_.sin_addr);
00081 # endif
00082 #endif
00083 }
00084
00085
00086
00087 ACE_INLINE u_short
00088 ACE_INET_Addr::get_port_number (void) const
00089 {
00090 ACE_TRACE ("ACE_INET_Addr::get_port_number");
00091 #if defined (ACE_HAS_IPV6)
00092 if (this->get_type () == PF_INET)
00093 return ACE_NTOHS (this->inet_addr_.in4_.sin_port);
00094 else
00095 return ACE_NTOHS (this->inet_addr_.in6_.sin6_port);
00096 #else
00097 return ACE_NTOHS (this->inet_addr_.in4_.sin_port);
00098 #endif
00099 }
00100
00101 ACE_INLINE int
00102 ACE_INET_Addr::get_addr_size (void) const
00103 {
00104 ACE_TRACE ("ACE_INET_Addr::get_addr_size");
00105 #if defined (ACE_HAS_IPV6)
00106 if (this->get_type () == PF_INET)
00107 return sizeof this->inet_addr_.in4_;
00108 else
00109 return sizeof this->inet_addr_.in6_;
00110 #else
00111 return sizeof this->inet_addr_.in4_;
00112 #endif
00113 }
00114
00115 ACE_INLINE bool
00116 ACE_INET_Addr::operator < (const ACE_INET_Addr &rhs) const
00117 {
00118 #if defined (ACE_HAS_IPV6)
00119 if (this->get_type() != rhs.get_type())
00120 {
00121 return this->get_type() < rhs.get_type();
00122 }
00123
00124 if (this->get_type() == PF_INET6)
00125 {
00126 int memval = ACE_OS::memcmp (this->ip_addr_pointer(),
00127 rhs.ip_addr_pointer(),
00128 this->ip_addr_size());
00129
00130 return memval < 0
00131 || (memval == 0
00132 && (this->get_port_number() < rhs.get_port_number()
00133 || (this->get_port_number() == rhs.get_port_number()
00134 && this->inet_addr_.in6_.sin6_scope_id <
00135 rhs.inet_addr_.in6_.sin6_scope_id)));
00136 }
00137 #endif
00138
00139 return this->get_ip_address () < rhs.get_ip_address ()
00140 || (this->get_ip_address () == rhs.get_ip_address ()
00141 && this->get_port_number () < rhs.get_port_number ());
00142 }
00143
00144 #if defined (ACE_HAS_WCHAR)
00145 ACE_INLINE int
00146 ACE_INET_Addr::set (u_short port_number,
00147 const wchar_t host_name[],
00148 int encode,
00149 int address_family)
00150 {
00151 return this->set (port_number,
00152 ACE_Wide_To_Ascii (host_name).char_rep (),
00153 encode,
00154 address_family);
00155 }
00156
00157 ACE_INLINE int
00158 ACE_INET_Addr::set (const wchar_t port_name[],
00159 const wchar_t host_name[],
00160 const wchar_t protocol[])
00161 {
00162 return this->set (ACE_Wide_To_Ascii (port_name).char_rep (),
00163 ACE_Wide_To_Ascii (host_name).char_rep (),
00164 ACE_Wide_To_Ascii (protocol).char_rep ());
00165 }
00166
00167 ACE_INLINE int
00168 ACE_INET_Addr::set (const wchar_t port_name[],
00169 ACE_UINT32 ip_addr,
00170 const wchar_t protocol[])
00171 {
00172 return this->set (ACE_Wide_To_Ascii (port_name).char_rep (),
00173 ip_addr,
00174 ACE_Wide_To_Ascii (protocol).char_rep ());
00175 }
00176
00177 ACE_INLINE int
00178 ACE_INET_Addr::set (const wchar_t addr[], int address_family)
00179 {
00180 return this->set (ACE_Wide_To_Ascii (addr).char_rep (), address_family);
00181 }
00182
00183 #endif
00184
00185
00186 ACE_INLINE bool
00187 ACE_INET_Addr::is_any (void) const
00188 {
00189 #if defined (ACE_HAS_IPV6)
00190 if (this->get_type () == AF_INET6)
00191 return IN6_IS_ADDR_UNSPECIFIED (&this->inet_addr_.in6_.sin6_addr);
00192 #endif
00193
00194 return (this->inet_addr_.in4_.sin_addr.s_addr == INADDR_ANY);
00195 }
00196
00197
00198 ACE_INLINE bool
00199 ACE_INET_Addr::is_loopback (void) const
00200 {
00201 #if defined (ACE_HAS_IPV6)
00202 if (this->get_type () == AF_INET6)
00203 return IN6_IS_ADDR_LOOPBACK (&this->inet_addr_.in6_.sin6_addr);
00204 #endif
00205
00206
00207 return ((this->get_ip_address () & 0XFF000000) == (INADDR_LOOPBACK & 0XFF000000));
00208 }
00209
00210
00211 ACE_INLINE bool
00212 ACE_INET_Addr::is_multicast (void) const
00213 {
00214 #if defined (ACE_HAS_IPV6)
00215 if (this->get_type() == AF_INET6)
00216 return this->inet_addr_.in6_.sin6_addr.s6_addr[0] == 0xFF;
00217 #endif
00218 return
00219 (*static_cast<const unsigned char*> (
00220 static_cast<const void*> (&this->inet_addr_.in4_.sin_addr.s_addr)) & 0xf0) == 0xe0;
00221 }
00222
00223 #if defined (ACE_HAS_IPV6)
00224
00225 ACE_INLINE bool
00226 ACE_INET_Addr::is_linklocal (void) const
00227 {
00228 if (this->get_type () == AF_INET6)
00229 return IN6_IS_ADDR_LINKLOCAL (&this->inet_addr_.in6_.sin6_addr);
00230
00231 return false;
00232 }
00233
00234
00235 ACE_INLINE bool
00236 ACE_INET_Addr::is_ipv4_mapped_ipv6 (void) const
00237 {
00238 if (this->get_type () == AF_INET6)
00239 return IN6_IS_ADDR_V4MAPPED (&this->inet_addr_.in6_.sin6_addr);
00240
00241 return false;
00242 }
00243
00244
00245 ACE_INLINE bool
00246 ACE_INET_Addr::is_ipv4_compat_ipv6 (void) const
00247 {
00248 if (this->get_type () == AF_INET6)
00249 return IN6_IS_ADDR_V4COMPAT (&this->inet_addr_.in6_.sin6_addr);
00250
00251 return false;
00252 }
00253 #endif
00254
00255 ACE_END_VERSIONED_NAMESPACE_DECL