00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Multihomed_INET_Addr.h 00006 * 00007 * $Id: Multihomed_INET_Addr.h 80826 2008-03-04 14:51:23Z wotte $ 00008 * 00009 * @author Edward R. Mulholland <emulholl@atl.lmco.com> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef ACE_MULTIHOMED_INET_ADDR_H 00014 #define ACE_MULTIHOMED_INET_ADDR_H 00015 00016 #include /**/ "ace/pre.h" 00017 00018 #include /**/ "ace/ACE_export.h" 00019 00020 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00021 # pragma once 00022 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00023 00024 #include "ace/INET_Addr.h" 00025 #include "ace/Containers_T.h" 00026 00027 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00028 00029 /** 00030 * @class ACE_Multihomed_INET_Addr 00031 * 00032 * @brief Extends ACE_INET_Addr with support for multi-homed 00033 * addresses. 00034 */ 00035 class ACE_Export ACE_Multihomed_INET_Addr : public ACE_INET_Addr 00036 { 00037 public: 00038 // = Initialization methods. 00039 00040 /// Default constructor. 00041 ACE_Multihomed_INET_Addr (void); 00042 00043 /** 00044 * Initializes an ACE_Multihomed_INET_Addr from the @a address, 00045 * which can be "ip-number:port-number" (e.g., "tango.cs.wustl.edu:1234" 00046 * or "128.252.166.57:1234"). If there is no ':' in the @a address it 00047 * is assumed to be a port number, with the IP address being 00048 * INADDR_ANY. 00049 */ 00050 explicit ACE_Multihomed_INET_Addr (const char address[]); 00051 00052 /** 00053 * Constructs an ACE_Multihomed_INET_Addr from a @a port_number, a 00054 * @a primary_host_name, and an array of <secondary_host_names>. 00055 * @a size is taken to be the length of the array. If @a encode is 00056 * non-zero, then @a port_number is converted into network byte 00057 * order; otherwise it is assumed to be in network byte order 00058 * already and is passed straight through. @a address_family can be 00059 * used to select IPv4/IPv6 if the OS has IPv6 capability 00060 * (ACE_HAS_IPV6 is defined). To specify IPv6, use the value 00061 * AF_INET6. To specify IPv4, use AF_INET. 00062 */ 00063 ACE_Multihomed_INET_Addr(u_short port_number, 00064 const char primary_host_name[], 00065 int encode = 1, 00066 int address_family = AF_UNSPEC, 00067 const char *(secondary_host_names[]) = 0, 00068 size_t size = 0); 00069 00070 /** 00071 * Constructs an ACE_Multihomed_INET_Addr from a @a port_number, 00072 * a @a primary_ip_addr, and an array of @a secondary_ip_addrs. @a 00073 * size is taken to be the length of the array. If @a encode is 00074 * non-zero, then the port number and the IP addresses are converted 00075 * into network byte order; otherwise they are assumed to be in 00076 * network byte order already and are passed straight through. 00077 */ 00078 ACE_Multihomed_INET_Addr(u_short port_number, 00079 ACE_UINT32 primary_ip_addr = INADDR_ANY, 00080 int encode = 1, 00081 const ACE_UINT32 *secondary_ip_addrs = 0, 00082 size_t size = 0); 00083 00084 #if defined (ACE_HAS_WCHAR) 00085 /** 00086 * WCHAR versions of the methods that take char's as arguments. 00087 */ 00088 ACE_Multihomed_INET_Addr(u_short port_number, 00089 const wchar_t primary_host_name[], 00090 int encode = 1, 00091 int address_family = AF_UNSPEC, 00092 const wchar_t *(secondary_host_names[]) = 0, 00093 size_t size = 0); 00094 int set (u_short port_number, 00095 const wchar_t primary_host_name[], 00096 int encode = 1, 00097 int address_family = AF_UNSPEC, 00098 const wchar_t *(secondary_host_names[]) = 0, 00099 size_t size = 0); 00100 00101 #endif /* ACE_HAS_WCHAR */ 00102 00103 /// Use compiler-generated copy constructor. 00104 00105 /// Use compiler-generated assignment operator. 00106 00107 /// Default dtor. 00108 ~ACE_Multihomed_INET_Addr (void); 00109 00110 // = Direct initialization methods. 00111 00112 // These methods are useful after the object has been constructed. 00113 00114 /** 00115 * Initializes an ACE_Multihomed_INET_Addr from a @a port_number, a 00116 * @a primary_host_name, and an array of <secondary_host_names>. 00117 * @a size is taken to be the length of the array. If @a encode is 00118 * non-zero, then @a port_number is converted into network byte 00119 * order; otherwise it is assumed to be in network byte order 00120 * already and is passed straight through. @a address_family can be 00121 * used to select IPv4/IPv6 if the OS has IPv6 capability 00122 * (ACE_HAS_IPV6 is defined). To specify IPv6, use the value 00123 * AF_INET6. To specify IPv4, use AF_INET. 00124 */ 00125 int set (u_short port_number, 00126 const char primary_host_name[], 00127 int encode = 1, 00128 int address_family = AF_UNSPEC, 00129 const char *(secondary_host_names[]) = 0, 00130 size_t size = 0); 00131 00132 /** 00133 * Initializes an ACE_Multihomed_INET_Addr from a @a port_number, 00134 * a @a primary_ip_addr, and an array of @a secondary_ip_addrs. @a 00135 * size is taken to be the length of the array. If @a encode is 00136 * non-zero, then the port number and the IP addresses are converted 00137 * into network byte order; otherwise they are assumed to be in 00138 * network byte order already and are passed straight through. 00139 */ 00140 int set (u_short port_number, 00141 ACE_UINT32 primary_ip_addr = INADDR_ANY, 00142 int encode = 1, 00143 const ACE_UINT32 *secondary_ip_addrs = 0, 00144 size_t size = 0); 00145 00146 /** 00147 * Sets the port number without affecting the host name. The port 00148 * numbers of the primary address, and of any and all secondary 00149 * addresses, are affected. If @a encode is enabled, then 00150 * @a port_number is converted into network byte order, otherwise it 00151 * is assumed to be in network byte order already and is passed 00152 * straight through. 00153 */ 00154 void set_port_number (u_short port_number, 00155 int encode = 1); 00156 00157 // = Accessor methods. 00158 00159 /** 00160 * Returns the number of secondary addresses. 00161 */ 00162 size_t get_num_secondary_addresses () const; 00163 00164 /** 00165 * Initialize user-supplied array @a secondary_addrs with the current 00166 * secondary addresses. @a size is taken as the size of this array. 00167 */ 00168 int get_secondary_addresses(ACE_INET_Addr *secondary_addrs, 00169 size_t size) const; 00170 00171 /** 00172 * Initialize user-supplied array @a addrs with the the current 00173 * primary and secondary addresses. @a size is taken as the size of 00174 * this array. 00175 */ 00176 void get_addresses(sockaddr_in *addrs, 00177 size_t size) const; 00178 00179 #if defined (ACE_HAS_IPV6) 00180 00181 /// IPV6 version of the above. 00182 void get_addresses(sockaddr_in6 *addrs, 00183 size_t size) const; 00184 #endif /* ACE_HAS_IPV6 */ 00185 00186 private: 00187 ACE_Array<ACE_INET_Addr> secondaries_; 00188 }; 00189 00190 ACE_END_VERSIONED_NAMESPACE_DECL 00191 00192 #if defined (__ACE_INLINE__) 00193 # include "ace/Multihomed_INET_Addr.inl" 00194 #endif /* __ACE_INLINE__ */ 00195 00196 #include /**/ "ace/post.h" 00197 00198 #endif /* ACE_MULTIHOMED_INET_ADDR_H */