Author: kgiusti
Date: Wed Apr  4 19:51:11 2012
New Revision: 1309569

URL: http://svn.apache.org/viewvc?rev=1309569&view=rev
Log:
QPID-3767: fix ipv6 address format bug.

Modified:
    qpid/branches/qpid-3767/qpid/cpp/src/qpid/broker/LinkRegistry.cpp

Modified: qpid/branches/qpid-3767/qpid/cpp/src/qpid/broker/LinkRegistry.cpp
URL: 
http://svn.apache.org/viewvc/qpid/branches/qpid-3767/qpid/cpp/src/qpid/broker/LinkRegistry.cpp?rev=1309569&r1=1309568&r2=1309569&view=diff
==============================================================================
--- qpid/branches/qpid-3767/qpid/cpp/src/qpid/broker/LinkRegistry.cpp (original)
+++ qpid/branches/qpid-3767/qpid/cpp/src/qpid/broker/LinkRegistry.cpp Wed Apr  
4 19:51:11 2012
@@ -267,21 +267,30 @@ namespace {
     {
         // Extract host and port of remote broker from connection id string.
         //
-        // TODO aconway 2011-02-01: centralize code that constructs/parses
-        // connection management IDs. Currently sys:: protocol factories
-        // and IO plugins construct the IDs and LinkRegistry parses them.
-        // current format assumed: "localhost:port-remotehost:port", asserts
-        // provided to alert us if this assumption changes!
+        // TODO aconway 2011-02-01: centralize code that constructs/parses 
connection
+        // management IDs. Currently sys:: protocol factories and IO plugins 
construct the
+        // IDs and LinkRegistry parses them.
+        // KAG: current connection id format assumed:
+        // "localhost:port-remotehost:port".  In the case of IpV6, the host 
addresses are
+        // contained within brackets "[...]", example:
+        // connId="[::1]:36859-[::1]:48603". Liberal use of "asserts" provided 
to alert us
+        // if this assumption changes!
         size_t separator = connId.find('-');
         assert(separator != std::string::npos);
         std::string remote = connId.substr(separator+1, std::string::npos);
-        separator = remote.find(":");
+        separator = remote.rfind(":");
         assert(separator != std::string::npos);
         *host = remote.substr(0, separator);
         // IPv6 - host is bracketed by "[]", strip them
-        if ((*host)[0] == '[' && (*host)[host->length() - 1] == ']')
-            *host = host->substr(1, host->length() - 1);
-        *port = boost::lexical_cast<uint16_t>(remote.substr(separator+1, 
std::string::npos));
+        if ((*host)[0] == '[' && (*host)[host->length() - 1] == ']') {
+            *host = host->substr(1, host->length() - 2);
+        }
+        try {
+            *port = boost::lexical_cast<uint16_t>(remote.substr(separator+1, 
std::string::npos));
+        } catch (const boost::bad_lexical_cast&) {
+            QPID_LOG(error, "Invalid format for connection identifier! '" << 
connId << "'");
+            assert(false);
+        }
     }
 }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to