summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Mesnier <mesnierp@ociweb.com>2015-09-09 08:58:55 -0500
committerPhil Mesnier <mesnierp@ociweb.com>2015-09-09 08:58:55 -0500
commitb3dbea0479820e9ffc1aaf3edac3ae33eb7279f6 (patch)
tree2686d4cd6e86e2fad24731d21e610acf8ff4e06d
parentb4b415c7266ea88e3c44a27c91139425804dfd65 (diff)
parent46dae9e6dcf5bfd00096b6e9f24cced71df9e28a (diff)
downloadATCD-b3dbea0479820e9ffc1aaf3edac3ae33eb7279f6.tar.gz
Merge pull request #137 from pmesnier/master
fix for setting port number on an ACE_INET_Addr with a non-empty inet…
-rw-r--r--ACE/ace/INET_Addr.cpp16
-rw-r--r--ACE/tests/INET_Addr_Test.cpp27
2 files changed, 42 insertions, 1 deletions
diff --git a/ACE/ace/INET_Addr.cpp b/ACE/ace/INET_Addr.cpp
index 9e8dfb22f3a..63cfeead5ef 100644
--- a/ACE/ace/INET_Addr.cpp
+++ b/ACE/ace/INET_Addr.cpp
@@ -896,7 +896,21 @@ ACE_INET_Addr::set_port_number (u_short port_number,
this->inet_addr_.in6_.sin6_port = port_number;
else
#endif /* ACE_HAS_IPV6 */
- this->inet_addr_.in4_.sin_port = port_number;
+ this->inet_addr_.in4_.sin_port = port_number;
+
+ if (this->inet_addrs_.empty ())
+ return;
+ for (std::vector<union ip46>::iterator i = this->inet_addrs_.begin ();
+ i != this->inet_addrs_.end ();
+ i++)
+ {
+#if defined (ACE_HAS_IPV6)
+ if (this->get_type () == AF_INET6)
+ i->in6_.sin6_port = port_number;
+ else
+#endif /* ACE_HAS_IPV6 */
+ i->in4_.sin_port = port_number;
+ }
}
// returns -2 when the hostname is truncated
diff --git a/ACE/tests/INET_Addr_Test.cpp b/ACE/tests/INET_Addr_Test.cpp
index 2c272514a64..0910a62b24a 100644
--- a/ACE/tests/INET_Addr_Test.cpp
+++ b/ACE/tests/INET_Addr_Test.cpp
@@ -84,6 +84,30 @@ static bool test_tao_use (void)
return true;
}
+static bool test_port_assignment (void)
+{
+#if defined (ACE_HAS_IPV6)
+ ACE_INET_Addr addr1 (static_cast<unsigned short> (0), ACE_IPV6_ANY, AF_INET6);
+ ACE_INET_Addr addr2;
+
+ addr1.set_port_number (12345);
+ addr2.set (addr1);
+ if (addr1.get_port_number () != addr2.get_port_number ())
+ {
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("port number not properly copied. ")
+ ACE_TEXT ("addr1 port = %d addr2 port = %d\n"),
+ addr1.get_port_number (), addr2.get_port_number ()));
+ return false;
+ }
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Test Port Assignment passed\n")));
+#else
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Test Port Assignment is IPv6 only\n")));
+#endif /* ACE_HAS_IPV6 */
+ return true;
+}
static bool test_multiple (void)
{
@@ -466,6 +490,9 @@ int run_main (int, ACE_TCHAR *[])
if (!test_multiple ())
status = 1;
+ if (!test_port_assignment ())
+ status = 1;
+
ACE_INET_Addr a1 (80, "127.0.0.1");
ACE_INET_Addr a2 = a1;
if (a1 != a2)