diff options
author | Kenneth Anthony Giusti <kgiusti@apache.org> | 2012-04-04 19:51:11 +0000 |
---|---|---|
committer | Kenneth Anthony Giusti <kgiusti@apache.org> | 2012-04-04 19:51:11 +0000 |
commit | 965b08e4d6c4eee7fe0d93126d373a19e22716e9 (patch) | |
tree | b0f0a47971ddd5c4fd4e5b1b19a66f18868c0141 | |
parent | 43c80059b846b446280ff10fb6523436326f69bb (diff) | |
download | qpid-python-965b08e4d6c4eee7fe0d93126d373a19e22716e9.tar.gz |
QPID-3767: fix ipv6 address format bug.
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/qpid-3767@1309569 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/cpp/src/qpid/broker/LinkRegistry.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/qpid/cpp/src/qpid/broker/LinkRegistry.cpp b/qpid/cpp/src/qpid/broker/LinkRegistry.cpp index a0cf3555c3..0a034ee206 100644 --- a/qpid/cpp/src/qpid/broker/LinkRegistry.cpp +++ b/qpid/cpp/src/qpid/broker/LinkRegistry.cpp @@ -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); + } } } |