void ACE_Multihomed_INET_Addr::get_addresses(sockaddr_in6 *addrs, size_t size) const { if (size == 0) return; // Copy primary address(es) to the first slot(s) of the user-supplied array ACE_INET_Addr me (*this); size_t i = 0; for (i = 0; i < size; ++i) { sockaddr_in6 *in6 = reinterpret_cast<sockaddr_in6*> (me.get_addr ()); if (in6->sin6_family == AF_INET6) { addrs[i] = *in6; ++i; } if (!me.next ()) break; } // Copy secondary addresses to remaining slots of the user-supplied // array. Secondary address [i] is copied to slot [i+1] for (size_t j = 0; j < this->secondaries_.size (); ++j) { ACE_INET_Addr copy (this->secondaries_[j]); for (; i < size; ++i) { sockaddr_in6 *in6 = reinterpret_cast<sockaddr_in6*> (copy.get_addr ()); if (in6->sin6_family == AF_INET6) { addrs[i] = *in6; ++i; } if (!copy.next ()) break; } } }
static bool test_multiple (void) { bool success = true; // Check the behavior when there are multiple addresses assigned to a name. // The NTP pool should always return multiples, though always different. ACE_INET_Addr ntp; if (ntp.set (123, ACE_TEXT ("pool.ntp.org")) == -1) { // This is just a warning to prevent fails on lookups on hosts with no // DNS service. The real value of this test is to accurately get // multiples from the result. ACE_ERROR ((LM_WARNING, ACE_TEXT ("%p\n"), ACE_TEXT ("pool.ntp.org"))); return true; } size_t count = 0; ACE_TCHAR addr_string[256]; do { ++count; // If lookup succeeded, there's at least one ntp.addr_to_string (addr_string, sizeof (addr_string)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("IPv4 %B: %s\n"), count, addr_string)); } while (ntp.next ()); success = count > 1; #if defined (ACE_HAS_IPV6) ACE_INET_Addr ntp6; if (ntp6.set (123, ACE_TEXT ("2.pool.ntp.org"), 1, AF_INET6) == -1) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("2.pool.ntp.org"))); return false; } count = 0; do { ++count; // If lookup succeeded, there's at least one ntp6.addr_to_string (addr_string, sizeof (addr_string)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("IPv6 %B: %s\n"), count, addr_string)); } while (ntp6.next ()); if (count <= 1) success = false; #endif /* ACE_HAS_IPV6 */ return success; }