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 ntohs (this->inet_addr_.in4_.sin_port);
00094 else
00095 return ntohs (this->inet_addr_.in6_.sin6_port);
00096 #else
00097 return 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 return this->get_ip_address () < rhs.get_ip_address ()
00119 || (this->get_ip_address () == rhs.get_ip_address ()
00120 && this->get_port_number () < rhs.get_port_number ());
00121 }
00122
00123 #if defined (ACE_HAS_WCHAR)
00124 ACE_INLINE int
00125 ACE_INET_Addr::set (u_short port_number,
00126 const wchar_t host_name[],
00127 int encode,
00128 int address_family)
00129 {
00130 return this->set (port_number,
00131 ACE_Wide_To_Ascii (host_name).char_rep (),
00132 encode,
00133 address_family);
00134 }
00135
00136 ACE_INLINE int
00137 ACE_INET_Addr::set (const wchar_t port_name[],
00138 const wchar_t host_name[],
00139 const wchar_t protocol[])
00140 {
00141 return this->set (ACE_Wide_To_Ascii (port_name).char_rep (),
00142 ACE_Wide_To_Ascii (host_name).char_rep (),
00143 ACE_Wide_To_Ascii (protocol).char_rep ());
00144 }
00145
00146 ACE_INLINE int
00147 ACE_INET_Addr::set (const wchar_t port_name[],
00148 ACE_UINT32 ip_addr,
00149 const wchar_t protocol[])
00150 {
00151 return this->set (ACE_Wide_To_Ascii (port_name).char_rep (),
00152 ip_addr,
00153 ACE_Wide_To_Ascii (protocol).char_rep ());
00154 }
00155
00156 ACE_INLINE int
00157 ACE_INET_Addr::set (const wchar_t addr[])
00158 {
00159 return this->set (ACE_Wide_To_Ascii (addr).char_rep ());
00160 }
00161
00162 #endif
00163
00164
00165 ACE_INLINE bool
00166 ACE_INET_Addr::is_any (void) const
00167 {
00168 #if defined (ACE_HAS_IPV6)
00169 if (this->get_type () == AF_INET6)
00170 return IN6_IS_ADDR_UNSPECIFIED (&this->inet_addr_.in6_.sin6_addr);
00171 #endif
00172
00173 return (this->inet_addr_.in4_.sin_addr.s_addr == INADDR_ANY);
00174 }
00175
00176
00177 ACE_INLINE bool
00178 ACE_INET_Addr::is_loopback (void) const
00179 {
00180 #if defined (ACE_HAS_IPV6)
00181 if (this->get_type () == AF_INET6)
00182 return IN6_IS_ADDR_LOOPBACK (&this->inet_addr_.in6_.sin6_addr);
00183 #endif
00184
00185 return (this->get_ip_address () == INADDR_LOOPBACK);
00186 }
00187
00188 #if defined (ACE_HAS_IPV6)
00189
00190 ACE_INLINE bool
00191 ACE_INET_Addr::is_linklocal (void) const
00192 {
00193 if (this->get_type () == AF_INET6)
00194 return IN6_IS_ADDR_LINKLOCAL (&this->inet_addr_.in6_.sin6_addr);
00195
00196 return false;
00197 }
00198
00199
00200 ACE_INLINE bool
00201 ACE_INET_Addr::is_ipv4_mapped_ipv6 (void) const
00202 {
00203 if (this->get_type () == AF_INET6)
00204 return IN6_IS_ADDR_V4MAPPED (&this->inet_addr_.in6_.sin6_addr);
00205
00206 return false;
00207 }
00208
00209
00210 ACE_INLINE bool
00211 ACE_INET_Addr::is_ipv4_compat_ipv6 (void) const
00212 {
00213 if (this->get_type () == AF_INET6)
00214 return IN6_IS_ADDR_V4COMPAT (&this->inet_addr_.in6_.sin6_addr);
00215
00216 return false;
00217 }
00218 #endif
00219
00220 ACE_END_VERSIONED_NAMESPACE_DECL