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_LACKS_NTOHS)
00092 ACE_NOTSUP_RETURN (0);
00093 #elif defined (ACE_HAS_IPV6)
00094 if (this->get_type () == PF_INET)
00095 return ntohs (this->inet_addr_.in4_.sin_port);
00096 else
00097 return ntohs (this->inet_addr_.in6_.sin6_port);
00098 #else
00099 return ntohs (this->inet_addr_.in4_.sin_port);
00100 #endif
00101 }
00102
00103 ACE_INLINE int
00104 ACE_INET_Addr::get_addr_size (void) const
00105 {
00106 ACE_TRACE ("ACE_INET_Addr::get_addr_size");
00107 #if defined (ACE_HAS_IPV6)
00108 if (this->get_type () == PF_INET)
00109 return sizeof this->inet_addr_.in4_;
00110 else
00111 return sizeof this->inet_addr_.in6_;
00112 #else
00113 return sizeof this->inet_addr_.in4_;
00114 #endif
00115 }
00116
00117 ACE_INLINE bool
00118 ACE_INET_Addr::operator < (const ACE_INET_Addr &rhs) const
00119 {
00120 #if defined (ACE_HAS_IPV6)
00121 if (this->get_type() != rhs.get_type())
00122 {
00123 return this->get_type() < rhs.get_type();
00124 }
00125
00126 if (this->get_type() == PF_INET6)
00127 {
00128 int memval = ACE_OS::memcmp (this->ip_addr_pointer(),
00129 rhs.ip_addr_pointer(),
00130 this->ip_addr_size());
00131
00132 return memval < 0
00133 || (memval == 0
00134 && (this->get_port_number() < rhs.get_port_number()
00135 || (this->get_port_number() == rhs.get_port_number()
00136 && this->inet_addr_.in6_.sin6_scope_id <
00137 rhs.inet_addr_.in6_.sin6_scope_id)));
00138 }
00139 #endif
00140
00141 return this->get_ip_address () < rhs.get_ip_address ()
00142 || (this->get_ip_address () == rhs.get_ip_address ()
00143 && this->get_port_number () < rhs.get_port_number ());
00144 }
00145
00146 #if defined (ACE_HAS_WCHAR)
00147 ACE_INLINE int
00148 ACE_INET_Addr::set (u_short port_number,
00149 const wchar_t host_name[],
00150 int encode,
00151 int address_family)
00152 {
00153 return this->set (port_number,
00154 ACE_Wide_To_Ascii (host_name).char_rep (),
00155 encode,
00156 address_family);
00157 }
00158
00159 ACE_INLINE int
00160 ACE_INET_Addr::set (const wchar_t port_name[],
00161 const wchar_t host_name[],
00162 const wchar_t protocol[])
00163 {
00164 return this->set (ACE_Wide_To_Ascii (port_name).char_rep (),
00165 ACE_Wide_To_Ascii (host_name).char_rep (),
00166 ACE_Wide_To_Ascii (protocol).char_rep ());
00167 }
00168
00169 ACE_INLINE int
00170 ACE_INET_Addr::set (const wchar_t port_name[],
00171 ACE_UINT32 ip_addr,
00172 const wchar_t protocol[])
00173 {
00174 return this->set (ACE_Wide_To_Ascii (port_name).char_rep (),
00175 ip_addr,
00176 ACE_Wide_To_Ascii (protocol).char_rep ());
00177 }
00178
00179 ACE_INLINE int
00180 ACE_INET_Addr::set (const wchar_t addr[], int address_family)
00181 {
00182 return this->set (ACE_Wide_To_Ascii (addr).char_rep (), address_family);
00183 }
00184
00185 #endif
00186
00187
00188 ACE_INLINE bool
00189 ACE_INET_Addr::is_any (void) const
00190 {
00191 #if defined (ACE_HAS_IPV6)
00192 if (this->get_type () == AF_INET6)
00193 return IN6_IS_ADDR_UNSPECIFIED (&this->inet_addr_.in6_.sin6_addr);
00194 #endif
00195
00196 return (this->inet_addr_.in4_.sin_addr.s_addr == INADDR_ANY);
00197 }
00198
00199
00200 ACE_INLINE bool
00201 ACE_INET_Addr::is_loopback (void) const
00202 {
00203 #if defined (ACE_HAS_IPV6)
00204 if (this->get_type () == AF_INET6)
00205 return IN6_IS_ADDR_LOOPBACK (&this->inet_addr_.in6_.sin6_addr);
00206 #endif
00207
00208
00209 return ((this->get_ip_address () & 0XFF000000) == (INADDR_LOOPBACK & 0XFF000000));
00210 }
00211
00212
00213 ACE_INLINE bool
00214 ACE_INET_Addr::is_multicast (void) const
00215 {
00216 #if defined (ACE_HAS_IPV6)
00217 if (this->get_type() == AF_INET6)
00218 return this->inet_addr_.in6_.sin6_addr.s6_addr[0] == 0xFF;
00219 #endif
00220 return
00221 this->inet_addr_.in4_.sin_addr.s_addr >= 0xE0000000 &&
00222 this->inet_addr_.in4_.sin_addr.s_addr <= 0xEFFFFFFF;
00223 }
00224
00225 #if defined (ACE_HAS_IPV6)
00226
00227 ACE_INLINE bool
00228 ACE_INET_Addr::is_linklocal (void) const
00229 {
00230 if (this->get_type () == AF_INET6)
00231 return IN6_IS_ADDR_LINKLOCAL (&this->inet_addr_.in6_.sin6_addr);
00232
00233 return false;
00234 }
00235
00236
00237 ACE_INLINE bool
00238 ACE_INET_Addr::is_ipv4_mapped_ipv6 (void) const
00239 {
00240 if (this->get_type () == AF_INET6)
00241 return IN6_IS_ADDR_V4MAPPED (&this->inet_addr_.in6_.sin6_addr);
00242
00243 return false;
00244 }
00245
00246
00247 ACE_INLINE bool
00248 ACE_INET_Addr::is_ipv4_compat_ipv6 (void) const
00249 {
00250 if (this->get_type () == AF_INET6)
00251 return IN6_IS_ADDR_V4COMPAT (&this->inet_addr_.in6_.sin6_addr);
00252
00253 return false;
00254 }
00255 #endif
00256
00257 ACE_END_VERSIONED_NAMESPACE_DECL