types: Add hash function for IPs
Change-Id: I232443d68aee32eb1d52c98ceecccd43700397a1
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/types.cpp b/src/types.cpp
index 0d642e5..12a4363 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -96,6 +96,17 @@
} // namespace phosphor::network::detail
+std::size_t std::hash<in_addr>::operator()(in_addr addr) const noexcept
+{
+ return std::hash<decltype(addr.s_addr)>{}(addr.s_addr);
+}
+
+std::size_t std::hash<in6_addr>::operator()(in6_addr addr) const noexcept
+{
+ return phosphor::network::hash_multi(addr.s6_addr32[0], addr.s6_addr32[1],
+ addr.s6_addr32[2], addr.s6_addr32[3]);
+}
+
std::string std::to_string(ether_addr value)
{
return string(phosphor::network::detail::AddrBufMaker<ether_addr>{}(value));
diff --git a/src/types.hpp b/src/types.hpp
index 53619ea..342c8cc 100644
--- a/src/types.hpp
+++ b/src/types.hpp
@@ -156,6 +156,18 @@
}
};
+template <>
+struct std::hash<in_addr>
+{
+ std::size_t operator()(in_addr addr) const noexcept;
+};
+
+template <>
+struct std::hash<in6_addr>
+{
+ std::size_t operator()(in6_addr addr) const noexcept;
+};
+
namespace fmt
{
template <>