summaryrefslogtreecommitdiff
path: root/ACE/ace/Multihomed_INET_Addr.cpp
diff options
context:
space:
mode:
authorSteve Huston <shuston@riverace.com>2015-03-06 16:09:47 -0500
committerSteve Huston <shuston@riverace.com>2015-03-06 16:09:47 -0500
commit7805370999f233118c5b3a7242b580d2d8214a0f (patch)
treed0741b91c346652294fc869d233978be351e97f7 /ACE/ace/Multihomed_INET_Addr.cpp
parentbcc16db982b483171996f2dfcedb132741c163f7 (diff)
downloadATCD-7805370999f233118c5b3a7242b580d2d8214a0f.tar.gz
Add ability for ACE_INET_Addr to hold all the addresses assigned to a name and allow ACE_Multihomed_INET_Addr to access them all.
Diffstat (limited to 'ACE/ace/Multihomed_INET_Addr.cpp')
-rw-r--r--ACE/ace/Multihomed_INET_Addr.cpp81
1 files changed, 59 insertions, 22 deletions
diff --git a/ACE/ace/Multihomed_INET_Addr.cpp b/ACE/ace/Multihomed_INET_Addr.cpp
index a734beb1ae2..1acc40c1053 100644
--- a/ACE/ace/Multihomed_INET_Addr.cpp
+++ b/ACE/ace/Multihomed_INET_Addr.cpp
@@ -243,21 +243,40 @@ void
ACE_Multihomed_INET_Addr::get_addresses(sockaddr_in *addrs,
size_t size) const
{
- // Copy primary address to the first slot of the user-supplied array
- if (size > 0) {
- addrs[0] = *reinterpret_cast<sockaddr_in*> (this->get_addr ());
- }
+ 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_in *in4 = reinterpret_cast<sockaddr_in*> (me.get_addr ());
+ if (in4->sin_family == AF_INET)
+ {
+ addrs[i] = *in4;
+ ++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]
-
- 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());
- }
+ for (size_t j = 0; j < this->secondaries_.size (); ++j)
+ {
+ ACE_INET_Addr copy (this->secondaries_[j]);
+ for (; i < size; ++i)
+ {
+ sockaddr_in *in4 = reinterpret_cast<sockaddr_in*> (copy.get_addr ());
+ if (in4->sin_family == AF_INET)
+ {
+ addrs[i] = *in4;
+ ++i;
+ }
+ if (!copy.next ())
+ break;
+ }
+ }
}
#if defined (ACE_HAS_IPV6)
@@ -265,22 +284,40 @@ void
ACE_Multihomed_INET_Addr::get_addresses(sockaddr_in6 *addrs,
size_t size) const
{
- // Copy primary address to the first slot of the user-supplied array
- if (size > 0)
+ 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)
{
- addrs[0] = *reinterpret_cast<sockaddr_in6*> (this->get_addr ());
+ 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]
- size_t top =
- size - 1 < this->secondaries_.size() ?
- size - 1 : this->secondaries_.size();
-
- for (size_t i = 0; i < top; ++i)
+ for (size_t j = 0; j < this->secondaries_.size (); ++j)
{
- addrs[i+1] =
- *reinterpret_cast<sockaddr_in6*> (this->secondaries_[i].get_addr());
+ 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;
+ }
}
}
#endif /* ACE_HAS_IPV6 */