Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

INET_Addr.i

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 // $Id: INET_Addr.i,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $
00003 
00004 // INET_Addr.i
00005 
00006 // Default dtor.
00007 ACE_INLINE
00008 ACE_INET_Addr::~ACE_INET_Addr (void)
00009 {
00010 }
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     this->inet_addr_.in4_.sin_family = AF_INET;
00018   }
00019 #if defined (ACE_HAS_IPV6)
00020   else if (this->get_type() == AF_INET6) {
00021     this->inet_addr_.in6_.sin6_family = AF_INET6;
00022   }
00023 #endif  /* ACE_HAS_IPV6 */
00024 }
00025 
00026 ACE_INLINE int
00027 ACE_INET_Addr::determine_type (void) const
00028 {
00029 #if defined (ACE_HAS_IPV6)
00030 #  if defined (ACE_USES_IPV4_IPV6_MIGRATION)
00031   return ACE_Sock_Connect::ipv6_enabled () ? AF_INET6 : AF_INET;
00032 #  else
00033   return AF_INET6;
00034 #  endif /* ACE_USES_IPV4_IPV6_MIGRATION */
00035 #endif /* ACE_HAS_IPV6 */
00036   return AF_INET;
00037 }
00038 
00039 ACE_INLINE void *
00040 ACE_INET_Addr::ip_addr_pointer (void) const
00041 {
00042 #if defined (ACE_HAS_IPV6)
00043   if (this->get_type () == PF_INET)
00044     return (void*)&this->inet_addr_.in4_.sin_addr;
00045   else
00046     return (void*)&this->inet_addr_.in6_.sin6_addr;
00047 #else
00048   return (void*)&this->inet_addr_.in4_.sin_addr;
00049 #endif
00050 }
00051 
00052 ACE_INLINE int
00053 ACE_INET_Addr::ip_addr_size (void) const
00054 {
00055   // Since this size value is used to pass to other host db-type
00056   // functions (gethostbyaddr, etc.) the length is of int type.
00057   // Thus, cast all these sizes back to int. They're all well
00058   // within the range of an int anyway.
00059 #if defined (ACE_HAS_IPV6)
00060   if (this->get_type () == PF_INET)
00061     return ACE_static_cast (int, sizeof this->inet_addr_.in4_.sin_addr);
00062   else
00063     return ACE_static_cast (int, sizeof this->inet_addr_.in6_.sin6_addr);
00064 #else
00065   // These _UNICOS changes were picked up from pre-IPv6 code in
00066   // get_host_name_i... the IPv6 section above may need something
00067   // similar, so keep an eye out for it.
00068 #  if !defined(_UNICOS)
00069   return ACE_static_cast (int, sizeof this->inet_addr_.in4_.sin_addr.s_addr);
00070 #  else /* _UNICOS */
00071   return ACE_static_cast (int, sizeof this->inet_addr_.in4_.sin_addr);
00072 #  endif /* ! _UNICOS */
00073 #endif /* ACE_HAS_IPV6 */
00074 }
00075 
00076 // Return the port number, converting it into host byte order...
00077 
00078 ACE_INLINE u_short
00079 ACE_INET_Addr::get_port_number (void) const
00080 {
00081   ACE_TRACE ("ACE_INET_Addr::get_port_number");
00082 #if defined (ACE_HAS_IPV6)
00083   if (this->get_type () == PF_INET)
00084     return ntohs (this->inet_addr_.in4_.sin_port);
00085   else
00086     return ntohs (this->inet_addr_.in6_.sin6_port);
00087 #else
00088   return ntohs (this->inet_addr_.in4_.sin_port);
00089 #endif /* ACE_HAS_IPV6 */
00090 }
00091 
00092 // Return the address.
00093 
00094 ACE_INLINE void *
00095 ACE_INET_Addr::get_addr (void) const
00096 {
00097   ACE_TRACE ("ACE_INET_Addr::get_addr");
00098   return (void*)&this->inet_addr_;
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 /* ACE_HAS_IPV6 */
00113 }
00114 
00115 
00116 ACE_INLINE u_long
00117 ACE_INET_Addr::hash (void) const
00118 {
00119 #if defined (ACE_HAS_IPV6)
00120   if (this->get_type () == PF_INET6)
00121     {
00122       const unsigned int *addr = (const unsigned int*)this->ip_addr_pointer();
00123       return addr[0] + addr[1] + addr[2] + addr[3] + this->get_port_number();
00124     }
00125   else
00126 #endif /* ACE_HAS_IPV6 */
00127   return this->get_ip_address () + this->get_port_number ();
00128 }
00129 
00130 ACE_INLINE int
00131 ACE_INET_Addr::operator < (const ACE_INET_Addr &rhs) const
00132 {
00133   return this->get_ip_address () < rhs.get_ip_address ()
00134     || (this->get_ip_address () == rhs.get_ip_address ()
00135         && this->get_port_number () < rhs.get_port_number ());
00136 }
00137 
00138 #if defined (ACE_HAS_WCHAR)
00139 ACE_INLINE int
00140 ACE_INET_Addr::set (u_short port_number,
00141                     const wchar_t host_name[],
00142                     int encode,
00143                     int address_family)
00144 {
00145   return this->set (port_number,
00146                     ACE_Wide_To_Ascii (host_name).char_rep (),
00147                     encode,
00148                     address_family);
00149 }
00150 
00151 ACE_INLINE int
00152 ACE_INET_Addr::set (const wchar_t port_name[],
00153                     const wchar_t host_name[],
00154                     const wchar_t protocol[])
00155 {
00156   return this->set (ACE_Wide_To_Ascii (port_name).char_rep (),
00157                     ACE_Wide_To_Ascii (host_name).char_rep (),
00158                     ACE_Wide_To_Ascii (protocol).char_rep ());
00159 }
00160 
00161 ACE_INLINE int
00162 ACE_INET_Addr::set (const wchar_t port_name[],
00163                     ACE_UINT32 ip_addr,
00164                     const wchar_t protocol[])
00165 {
00166   return this->set (ACE_Wide_To_Ascii (port_name).char_rep (),
00167                     ip_addr,
00168                     ACE_Wide_To_Ascii (protocol).char_rep ());
00169 }
00170 
00171 ACE_INLINE int
00172 ACE_INET_Addr::set (const wchar_t addr[])
00173 {
00174   return this->set (ACE_Wide_To_Ascii (addr).char_rep ());
00175 }
00176 
00177 #endif /* ACE_HAS_WCHAR */

Generated on Mon Jun 16 11:19:53 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002