Extends ACE_INET_Addr with support for multi-homed addresses. More...
#include <Multihomed_INET_Addr.h>
Public Member Functions | |
ACE_Multihomed_INET_Addr (void) | |
Default constructor. | |
ACE_Multihomed_INET_Addr (const char address[]) | |
ACE_Multihomed_INET_Addr (u_short port_number, const char primary_host_name[], int encode=1, int address_family=AF_UNSPEC, const char *(secondary_host_names[])=0, size_t size=0) | |
ACE_Multihomed_INET_Addr (u_short port_number, ACE_UINT32 primary_ip_addr=INADDR_ANY, int encode=1, const ACE_UINT32 *secondary_ip_addrs=0, size_t size=0) | |
~ACE_Multihomed_INET_Addr (void) | |
Use compiler-generated copy constructor. | |
int | set (u_short port_number, const char primary_host_name[], int encode=1, int address_family=AF_UNSPEC, const char *(secondary_host_names[])=0, size_t size=0) |
int | set (u_short port_number, ACE_UINT32 primary_ip_addr=INADDR_ANY, int encode=1, const ACE_UINT32 *secondary_ip_addrs=0, size_t size=0) |
void | set_port_number (u_short port_number, int encode=1) |
size_t | get_num_secondary_addresses () const |
int | get_secondary_addresses (ACE_INET_Addr *secondary_addrs, size_t size) const |
void | get_addresses (sockaddr_in *addrs, size_t size) const |
Private Attributes | |
ACE_Array< ACE_INET_Addr > | secondaries_ |
Extends ACE_INET_Addr with support for multi-homed addresses.
Definition at line 35 of file Multihomed_INET_Addr.h.
ACE_Multihomed_INET_Addr::ACE_Multihomed_INET_Addr | ( | void | ) |
Default constructor.
ACE_Multihomed_INET_Addr::ACE_Multihomed_INET_Addr | ( | const char | address[] | ) | [explicit] |
Initializes an ACE_Multihomed_INET_Addr from the address, which can be "ip-number:port-number" (e.g., "tango.cs.wustl.edu:1234" or "128.252.166.57:1234"). If there is no ':' in the address it is assumed to be a port number, with the IP address being INADDR_ANY.
Definition at line 28 of file Multihomed_INET_Addr.cpp.
: ACE_INET_Addr (address), secondaries_ (0) { }
ACE_Multihomed_INET_Addr::ACE_Multihomed_INET_Addr | ( | u_short | port_number, | |
const char | primary_host_name[], | |||
int | encode = 1 , |
|||
int | address_family = AF_UNSPEC , |
|||
const char * | secondary_host_names[] = 0 , |
|||
size_t | size = 0 | |||
) |
Constructs an ACE_Multihomed_INET_Addr from a port_number, a primary_host_name, and an array of <secondary_host_names>. size is taken to be the length of the array. If encode is non-zero, then port_number is converted into network byte order; otherwise it is assumed to be in network byte order already and is passed straight through. address_family can be used to select IPv4/IPv6 if the OS has IPv6 capability (ACE_HAS_IPV6 is defined). To specify IPv6, use the value AF_INET6. To specify IPv4, use AF_INET.
Definition at line 34 of file Multihomed_INET_Addr.cpp.
{ // Initialize the primary INET addr ACE_INET_Addr::set(port_number, host_name, encode, address_family); // check for secondary INET addrs if (secondary_host_names && size){ // we have a non-zero pointer and size this->secondaries_.size(size); // size the array size_t next_empty_slot = 0; for (size_t i = 0; i < size; ++i) { int ret = this->secondaries_[next_empty_slot].set(port_number, secondary_host_names[i], encode, address_family); if (ret) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Invalid INET addr (%C:%u) will be ignored\n"), secondary_host_names[i], port_number)); this->secondaries_.size(this->secondaries_.size() - 1); } else ++next_empty_slot; } } return; }
ACE_Multihomed_INET_Addr::ACE_Multihomed_INET_Addr | ( | u_short | port_number, | |
ACE_UINT32 | primary_ip_addr = INADDR_ANY , |
|||
int | encode = 1 , |
|||
const ACE_UINT32 * | secondary_ip_addrs = 0 , |
|||
size_t | size = 0 | |||
) |
Constructs an ACE_Multihomed_INET_Addr from a port_number, a primary_ip_addr, and an array of secondary_ip_addrs. size is taken to be the length of the array. If encode is non-zero, then the port number and the IP addresses are converted into network byte order; otherwise they are assumed to be in network byte order already and are passed straight through.
Definition at line 106 of file Multihomed_INET_Addr.cpp.
{ // Initialize the primary INET addr ACE_INET_Addr::set(port_number, primary_ip_addr, encode); // check for secondary INET addrs if (secondary_ip_addrs && size){ // we have a non-zero pointer and size this->secondaries_.size(size); // size the array size_t next_empty_slot = 0; for (size_t i = 0; i < size; ++i) { int const ret = this->secondaries_[next_empty_slot].set(port_number, secondary_ip_addrs[i], encode); if (ret) { ACE_DEBUG ((LM_DEBUG, "Invalid INET addr (%u:%u) will be ignored\n", secondary_ip_addrs[i], port_number)); this->secondaries_.size(this->secondaries_.size() - 1); } else ++next_empty_slot; } } return; }
ACE_Multihomed_INET_Addr::~ACE_Multihomed_INET_Addr | ( | void | ) |
Use compiler-generated copy constructor.
Use compiler-generated assignment operator. Default dtor.
Definition at line 295 of file Multihomed_INET_Addr.cpp.
{ }
void ACE_Multihomed_INET_Addr::get_addresses | ( | sockaddr_in * | addrs, | |
size_t | size | |||
) | const |
Initialize user-supplied array addrs with the the current primary and secondary addresses. size is taken as the size of this array.
Definition at line 249 of file Multihomed_INET_Addr.cpp.
{ // Copy primary address to the first slot of the user-supplied array if (size > 0) { addrs[0] = *reinterpret_cast<sockaddr_in*> (this->get_addr ()); } // Copy secondary addresses to remaining slots of the user-supplied // array. Secondary address [i] is copied to slot [i+1] size_t top = size - 1 < this->secondaries_.size() ? size - 1 : this->secondaries_.size(); for (size_t i = 0; i < top; ++i) { addrs[i+1] = *reinterpret_cast<sockaddr_in*> (this->secondaries_[i].get_addr()); } }
size_t ACE_Multihomed_INET_Addr::get_num_secondary_addresses | ( | ) | const [inline] |
Returns the number of secondary addresses.
Definition at line 10 of file Multihomed_INET_Addr.inl.
{ return this->secondaries_.size(); }
int ACE_Multihomed_INET_Addr::get_secondary_addresses | ( | ACE_INET_Addr * | secondary_addrs, | |
size_t | size | |||
) | const |
Initialize user-supplied array secondary_addrs with the current secondary addresses. size is taken as the size of this array.
Definition at line 228 of file Multihomed_INET_Addr.cpp.
{ size_t top = size < this->secondaries_.size() ? size : this->secondaries_.size(); for (size_t i = 0; i < top; ++i) { int ret = secondary_addrs[i].set (this->secondaries_[i]); if (ret) return ret; } return 0; }
int ACE_Multihomed_INET_Addr::set | ( | u_short | port_number, | |
ACE_UINT32 | primary_ip_addr = INADDR_ANY , |
|||
int | encode = 1 , |
|||
const ACE_UINT32 * | secondary_ip_addrs = 0 , |
|||
size_t | size = 0 | |||
) |
Initializes an ACE_Multihomed_INET_Addr from a port_number, a primary_ip_addr, and an array of secondary_ip_addrs. size is taken to be the length of the array. If encode is non-zero, then the port number and the IP addresses are converted into network byte order; otherwise they are assumed to be in network byte order already and are passed straight through.
Definition at line 195 of file Multihomed_INET_Addr.cpp.
{ this->secondaries_.size(size); for (size_t i = 0; i < size; ++i) { int ret = this->secondaries_[i].set(port_number, secondary_ip_addrs[i], encode); if (ret) { return ret; } } return ACE_INET_Addr::set(port_number, primary_ip_addr, encode); }
int ACE_Multihomed_INET_Addr::set | ( | u_short | port_number, | |
const char | primary_host_name[], | |||
int | encode = 1 , |
|||
int | address_family = AF_UNSPEC , |
|||
const char * | secondary_host_names[] = 0 , |
|||
size_t | size = 0 | |||
) |
Initializes an ACE_Multihomed_INET_Addr from a port_number, a primary_host_name, and an array of <secondary_host_names>. size is taken to be the length of the array. If encode is non-zero, then port_number is converted into network byte order; otherwise it is assumed to be in network byte order already and is passed straight through. address_family can be used to select IPv4/IPv6 if the OS has IPv6 capability (ACE_HAS_IPV6 is defined). To specify IPv6, use the value AF_INET6. To specify IPv4, use AF_INET.
Definition at line 142 of file Multihomed_INET_Addr.cpp.
{ this->secondaries_.size(size); for (size_t i = 0; i < size; ++i) { int const ret = this->secondaries_[i].set(port_number, secondary_host_names[i], encode, address_family); if (ret) { return ret; } } return ACE_INET_Addr::set(port_number, host_name, encode, address_family); }
void ACE_Multihomed_INET_Addr::set_port_number | ( | u_short | port_number, | |
int | encode = 1 | |||
) |
Sets the port number without affecting the host name. The port numbers of the primary address, and of any and all secondary addresses, are affected. If encode is enabled, then port_number is converted into network byte order, otherwise it is assumed to be in network byte order already and is passed straight through.
Reimplemented from ACE_INET_Addr.
Definition at line 218 of file Multihomed_INET_Addr.cpp.
{ size_t i = 0; while (i < secondaries_.size()) secondaries_[i++].set_port_number(port_number, encode); this->ACE_INET_Addr::set_port_number(port_number, encode); }
Definition at line 188 of file Multihomed_INET_Addr.h.