face: Prevent infinite loop in TcpFactory and UdpFactory
Change-Id: Idd694bc08033c524f3c0e569ed74341aa33fce31
Refs: #2292
diff --git a/core/network-interface.cpp b/core/network-interface.cpp
index d7eebbd..1aad63e 100644
--- a/core/network-interface.cpp
+++ b/core/network-interface.cpp
@@ -54,9 +54,25 @@
"NetworkInterfaceInfo must provide a default constructor");
#endif
+#ifdef WITH_TESTS
+static shared_ptr<std::vector<NetworkInterfaceInfo>> s_debugNetworkInterfaces = nullptr;
+
+void
+setDebugNetworkInterfaces(shared_ptr<std::vector<NetworkInterfaceInfo>> interfaces)
+{
+ s_debugNetworkInterfaces = interfaces;
+}
+#endif
+
std::vector<NetworkInterfaceInfo>
listNetworkInterfaces()
{
+#ifdef WITH_TESTS
+ if (s_debugNetworkInterfaces != nullptr) {
+ return *s_debugNetworkInterfaces;
+ }
+#endif
+
using namespace boost::asio::ip;
using std::strerror;
diff --git a/core/network-interface.hpp b/core/network-interface.hpp
index 8519db1..e9be083 100644
--- a/core/network-interface.hpp
+++ b/core/network-interface.hpp
@@ -88,9 +88,19 @@
return (flags & IFF_UP) != 0;
}
+/** \brief List configured network interfaces on the system and their info
+ */
std::vector<NetworkInterfaceInfo>
listNetworkInterfaces();
+#ifdef WITH_TESTS
+/** \brief Set a list of network interfaces to be returned by subsequent listNetworkInterfaces call
+ * \note To reset to normal behavior, use `setDebugNetworkInterfaces(nullptr);`
+ */
+void
+setDebugNetworkInterfaces(shared_ptr<std::vector<NetworkInterfaceInfo>> interfaces);
+#endif
+
} // namespace nfd
#endif // NFD_CORE_NETWORK_INTERFACE_HPP