3 //=============================================================================
5 * @file Multihomed_INET_Addr.h
7 * $Id: Multihomed_INET_Addr.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Edward R. Mulholland <emulholl@atl.lmco.com>
11 //=============================================================================
13 #ifndef ACE_MULTIHOMED_INET_ADDR_H
14 #define ACE_MULTIHOMED_INET_ADDR_H
16 #include /**/ "ace/pre.h"
18 #include /**/ "ace/ACE_export.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "ace/INET_Addr.h"
25 #include "ace/Containers_T.h"
27 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 * @class ACE_Multihomed_INET_Addr
32 * @brief Extends ACE_INET_Addr with support for multi-homed
35 class ACE_Export ACE_Multihomed_INET_Addr
: public ACE_INET_Addr
38 // = Initialization methods.
40 /// Default constructor.
41 ACE_Multihomed_INET_Addr (void);
44 * Initializes an ACE_Multihomed_INET_Addr from the @a address,
45 * which can be "ip-number:port-number" (e.g., "tango.cs.wustl.edu:1234"
46 * or "128.252.166.57:1234"). If there is no ':' in the @a address it
47 * is assumed to be a port number, with the IP address being
50 explicit ACE_Multihomed_INET_Addr (const char address
[]);
53 * Constructs an ACE_Multihomed_INET_Addr from a @a port_number, a
54 * @a primary_host_name, and an array of <secondary_host_names>.
55 * @a size is taken to be the length of the array. If @a encode is
56 * non-zero, then @a port_number is converted into network byte
57 * order; otherwise it is assumed to be in network byte order
58 * already and is passed straight through. @a address_family can be
59 * used to select IPv4/IPv6 if the OS has IPv6 capability
60 * (ACE_HAS_IPV6 is defined). To specify IPv6, use the value
61 * AF_INET6. To specify IPv4, use AF_INET.
63 ACE_Multihomed_INET_Addr(u_short port_number
,
64 const char primary_host_name
[],
66 int address_family
= AF_UNSPEC
,
67 const char *(secondary_host_names
[]) = 0,
71 * Constructs an ACE_Multihomed_INET_Addr from a @a port_number,
72 * a @a primary_ip_addr, and an array of @a secondary_ip_addrs. @a
73 * size is taken to be the length of the array. If @a encode is
74 * non-zero, then the port number and the IP addresses are converted
75 * into network byte order; otherwise they are assumed to be in
76 * network byte order already and are passed straight through.
78 ACE_Multihomed_INET_Addr(u_short port_number
,
79 ACE_UINT32 primary_ip_addr
= INADDR_ANY
,
81 const ACE_UINT32
*secondary_ip_addrs
= 0,
84 #if defined (ACE_HAS_WCHAR)
86 * WCHAR versions of the methods that take char's as arguments.
88 ACE_Multihomed_INET_Addr(u_short port_number
,
89 const wchar_t primary_host_name
[],
91 int address_family
= AF_UNSPEC
,
92 const wchar_t *(secondary_host_names
[]) = 0,
94 int set (u_short port_number
,
95 const wchar_t primary_host_name
[],
97 int address_family
= AF_UNSPEC
,
98 const wchar_t *(secondary_host_names
[]) = 0,
101 #endif /* ACE_HAS_WCHAR */
103 /// Use compiler-generated copy constructor.
105 /// Use compiler-generated assignment operator.
108 ~ACE_Multihomed_INET_Addr (void);
110 // = Direct initialization methods.
112 // These methods are useful after the object has been constructed.
115 * Initializes an ACE_Multihomed_INET_Addr from a @a port_number, a
116 * @a primary_host_name, and an array of <secondary_host_names>.
117 * @a size is taken to be the length of the array. If @a encode is
118 * non-zero, then @a port_number is converted into network byte
119 * order; otherwise it is assumed to be in network byte order
120 * already and is passed straight through. @a address_family can be
121 * used to select IPv4/IPv6 if the OS has IPv6 capability
122 * (ACE_HAS_IPV6 is defined). To specify IPv6, use the value
123 * AF_INET6. To specify IPv4, use AF_INET.
125 int set (u_short port_number
,
126 const char primary_host_name
[],
128 int address_family
= AF_UNSPEC
,
129 const char *(secondary_host_names
[]) = 0,
133 * Initializes an ACE_Multihomed_INET_Addr from a @a port_number,
134 * a @a primary_ip_addr, and an array of @a secondary_ip_addrs. @a
135 * size is taken to be the length of the array. If @a encode is
136 * non-zero, then the port number and the IP addresses are converted
137 * into network byte order; otherwise they are assumed to be in
138 * network byte order already and are passed straight through.
140 int set (u_short port_number
,
141 ACE_UINT32 primary_ip_addr
= INADDR_ANY
,
143 const ACE_UINT32
*secondary_ip_addrs
= 0,
147 * Sets the port number without affecting the host name. The port
148 * numbers of the primary address, and of any and all secondary
149 * addresses, are affected. If @a encode is enabled, then
150 * @a port_number is converted into network byte order, otherwise it
151 * is assumed to be in network byte order already and is passed
154 void set_port_number (u_short port_number
,
157 // = Accessor methods.
160 * Returns the number of secondary addresses.
162 size_t get_num_secondary_addresses () const;
165 * Initialize user-supplied array @a secondary_addrs with the current
166 * secondary addresses. @a size is taken as the size of this array.
168 int get_secondary_addresses(ACE_INET_Addr
*secondary_addrs
,
172 * Initialize user-supplied array @a addrs with the the current
173 * primary and secondary addresses. @a size is taken as the size of
176 void get_addresses(sockaddr_in
*addrs
,
179 #if defined (ACE_HAS_IPV6)
181 /// IPV6 version of the above.
182 void get_addresses(sockaddr_in6
*addrs
,
184 #endif /* ACE_HAS_IPV6 */
187 ACE_Array
<ACE_INET_Addr
> secondaries_
;
190 ACE_END_VERSIONED_NAMESPACE_DECL
192 #if defined (__ACE_INLINE__)
193 # include "ace/Multihomed_INET_Addr.inl"
194 #endif /* __ACE_INLINE__ */
196 #include /**/ "ace/post.h"
198 #endif /* ACE_MULTIHOMED_INET_ADDR_H */