core: FaceUri recognizes IPv4-mapped IPv6 address
refs #1635
Change-Id: I5fc54b3945fc77869a4531a31c1fc27e7c434447
diff --git a/core/face-uri.cpp b/core/face-uri.cpp
index 2969e20..47c265e 100644
--- a/core/face-uri.cpp
+++ b/core/face-uri.cpp
@@ -5,7 +5,8 @@
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
- * Beijing Institute of Technology
+ * Beijing Institute of Technology,
+ * The University of Memphis
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
@@ -71,6 +72,8 @@
static const boost::regex v6Exp("^\\[([a-fA-F0-9:]+)\\](?:\\:(\\d+))?$");
// pattern for Ethernet address in standard hex-digits-and-colons notation
static const boost::regex etherExp("^\\[((?:[a-fA-F0-9]{1,2}\\:){5}(?:[a-fA-F0-9]{1,2}))\\]$");
+ // pattern for IPv4-mapped IPv6 address, with optional port number
+ static const boost::regex v4MappedV6Exp("^\\[::ffff:(\\d+(?:\\.\\d+){3})\\](?:\\:(\\d+))?$");
// pattern for IPv4/hostname/fd/ifname, with optional port number
static const boost::regex v4HostExp("^([^:]+)(?:\\:(\\d+))?$");
@@ -82,6 +85,7 @@
m_isV6 = boost::regex_match(authority, match, v6Exp);
if (m_isV6 ||
boost::regex_match(authority, match, etherExp) ||
+ boost::regex_match(authority, match, v4MappedV6Exp) ||
boost::regex_match(authority, match, v4HostExp)) {
m_host = match[1];
m_port = match[2];
diff --git a/tests/core/face-uri.cpp b/tests/core/face-uri.cpp
index e1e07a9..c3060fd 100644
--- a/tests/core/face-uri.cpp
+++ b/tests/core/face-uri.cpp
@@ -5,7 +5,8 @@
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
- * Beijing Institute of Technology
+ * Beijing Institute of Technology,
+ * The University of Memphis
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
@@ -186,6 +187,18 @@
BOOST_CHECK_EQUAL(FaceUri::fromDev(ifname).toString(), "dev://en1");
}
+BOOST_AUTO_TEST_CASE(Bug1635)
+{
+ FaceUri uri;
+
+ BOOST_CHECK(uri.parse("wsclient://[::ffff:76.90.11.239]:56366"));
+ BOOST_CHECK_EQUAL(uri.getScheme(), "wsclient");
+ BOOST_CHECK_EQUAL(uri.getHost(), "76.90.11.239");
+ BOOST_CHECK_EQUAL(uri.getPort(), "56366");
+ BOOST_CHECK_EQUAL(uri.getPath(), "");
+ BOOST_CHECK_EQUAL(uri.toString(), "wsclient://76.90.11.239:56366");
+}
+
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests