util: FaceUri: port numbers are 16 bits wide
Change-Id: I9568df121bac150bc98071820a5cd212fb22a458
diff --git a/src/util/face-uri.cpp b/src/util/face-uri.cpp
index fea4e16..f38e8c2 100644
--- a/src/util/face-uri.cpp
+++ b/src/util/face-uri.cpp
@@ -310,8 +310,8 @@
protected:
explicit
IpHostCanonizeProvider(const std::string& baseScheme,
- uint32_t defaultUnicastPort = 6363,
- uint32_t defaultMulticastPort = 56363)
+ uint16_t defaultUnicastPort = 6363,
+ uint16_t defaultMulticastPort = 56363)
: m_baseScheme(baseScheme)
, m_v4Scheme(baseScheme + "4")
, m_v6Scheme(baseScheme + "6")
@@ -334,15 +334,15 @@
return;
}
- uint32_t port = 0;
+ uint16_t port = 0;
if (faceUri->getPort().empty()) {
port = ipAddress.is_multicast() ? m_defaultMulticastPort : m_defaultUnicastPort;
}
else {
try {
- port = boost::lexical_cast<uint32_t>(faceUri->getPort());
+ port = boost::lexical_cast<uint16_t>(faceUri->getPort());
}
- catch (boost::bad_lexical_cast&) {
+ catch (const boost::bad_lexical_cast&) {
onFailure("invalid port number");
return;
}
@@ -375,8 +375,8 @@
std::string m_baseScheme;
std::string m_v4Scheme;
std::string m_v6Scheme;
- uint32_t m_defaultUnicastPort;
- uint32_t m_defaultMulticastPort;
+ uint16_t m_defaultUnicastPort;
+ uint16_t m_defaultMulticastPort;
};
class UdpCanonizeProvider : public IpHostCanonizeProvider<boost::asio::ip::udp>
diff --git a/tests/unit-tests/util/face-uri.t.cpp b/tests/unit-tests/util/face-uri.t.cpp
index 6cf52d9..b63c2de 100644
--- a/tests/unit-tests/util/face-uri.t.cpp
+++ b/tests/unit-tests/util/face-uri.t.cpp
@@ -207,6 +207,7 @@
addTest("udp4://192.0.2.5:9695", true, "udp4://192.0.2.5:9695");
addTest("udp4://192.0.2.666:6363", false, "");
addTest("udp4://google-public-dns-a.google.com", true, "udp4://8.8.8.8:6363");
+ addTest("udp4://google-public-dns-a.google.com:70000", false, "");
addTest("udp4://invalid.invalid", false, "");
// IPv4 multicast
@@ -223,9 +224,12 @@
// IPv6 unicast
addTest("udp6://[2001:db8::1]:6363", true, "udp6://[2001:db8::1]:6363");
+ addTest("udp6://[2001:db8::1]", true, "udp6://[2001:db8::1]:6363");
addTest("udp://[2001:db8::1]:6363", true, "udp6://[2001:db8::1]:6363");
addTest("udp6://[2001:db8::01]:6363", true, "udp6://[2001:db8::1]:6363");
+ addTest("udp6://[2001::db8::1]:6363", false, "");
addTest("udp6://google-public-dns-a.google.com", true, "udp6://[2001:4860:4860::8888]:6363");
+ addTest("udp6://google-public-dns-a.google.com:70000", false, "");
addTest("udp6://invalid.invalid", false, "");
addTest("udp://invalid.invalid", false, "");
@@ -292,6 +296,7 @@
addTest("tcp4://192.0.2.5:9695", true, "tcp4://192.0.2.5:9695");
addTest("tcp4://192.0.2.666:6363", false, "");
addTest("tcp4://google-public-dns-a.google.com", true, "tcp4://8.8.8.8:6363");
+ addTest("tcp4://google-public-dns-a.google.com:70000", false, "");
addTest("tcp4://invalid.invalid", false, "");
// IPv4 multicast
@@ -308,9 +313,12 @@
// IPv6 unicast
addTest("tcp6://[2001:db8::1]:6363", true, "tcp6://[2001:db8::1]:6363");
+ addTest("tcp6://[2001:db8::1]", true, "tcp6://[2001:db8::1]:6363");
addTest("tcp://[2001:db8::1]:6363", true, "tcp6://[2001:db8::1]:6363");
addTest("tcp6://[2001:db8::01]:6363", true, "tcp6://[2001:db8::1]:6363");
+ addTest("tcp6://[2001::db8::1]:6363", false, "");
addTest("tcp6://google-public-dns-a.google.com", true, "tcp6://[2001:4860:4860::8888]:6363");
+ addTest("tcp6://google-public-dns-a.google.com:70000", false, "");
addTest("tcp6://invalid.invalid", false, "");
addTest("tcp://invalid.invalid", false, "");