util: Simplify addFromBuf

Change-Id: I4d1a133e4c4ab738e0ed190446efc663ffe9a373
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/util.cpp b/src/util.cpp
index 03d7398..f6880c3 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -17,8 +17,6 @@
 #endif
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/log.hpp>
-#include <stdexcept>
-#include <stdplus/raw.hpp>
 #include <string>
 #include <string_view>
 #include <variant>
@@ -131,32 +129,6 @@
 
 } // namespace internal
 
-constexpr auto familyVisit(auto&& visitor, int family)
-{
-    if (family == AF_INET)
-    {
-        return visitor.template operator()<AF_INET>();
-    }
-    else if (family == AF_INET6)
-    {
-        return visitor.template operator()<AF_INET6>();
-    }
-    throw std::invalid_argument("Invalid addr family");
-}
-
-template <int family>
-typename FamilyTraits<family>::addr addrFromBuf(std::string_view buf)
-{
-    return stdplus::raw::copyFromStrict<typename FamilyTraits<family>::addr>(
-        buf);
-}
-
-InAddrAny addrFromBuf(int family, std::string_view buf)
-{
-    return familyVisit(
-        [=]<int f>() -> InAddrAny { return addrFromBuf<f>(buf); }, family);
-}
-
 void deleteInterface(stdplus::const_zstring intf)
 {
     pid_t pid = fork();
diff --git a/src/util.hpp b/src/util.hpp
index 93b2925..3638160 100644
--- a/src/util.hpp
+++ b/src/util.hpp
@@ -9,6 +9,7 @@
 #include <filesystem>
 #include <optional>
 #include <sdbusplus/bus.hpp>
+#include <stdplus/raw.hpp>
 #include <stdplus/zstring.hpp>
 #include <string>
 #include <string_view>
@@ -56,31 +57,22 @@
 
 } // namespace mac_address
 
-template <int family>
-struct FamilyTraits
-{
-};
-
-template <>
-struct FamilyTraits<AF_INET>
-{
-    using addr = in_addr;
-};
-
-template <>
-struct FamilyTraits<AF_INET6>
-{
-    using addr = in6_addr;
-};
-
 /* @brief converts a sockaddr for the specified address family into
  *        a type_safe InAddrAny.
  * @param[in] family - The address family of the buf
  * @param[in] buf - The network byte order address
  */
-template <int family>
-typename FamilyTraits<family>::addr addrFromBuf(std::string_view buf);
-InAddrAny addrFromBuf(int family, std::string_view buf);
+constexpr InAddrAny addrFromBuf(int family, std::string_view buf)
+{
+    switch (family)
+    {
+        case AF_INET:
+            return stdplus::raw::copyFromStrict<in_addr>(buf);
+        case AF_INET6:
+            return stdplus::raw::copyFromStrict<in6_addr>(buf);
+    }
+    throw std::invalid_argument("Unrecognized family");
+}
 
 /** @brief Delete the given interface.
  *  @param[in] intf - interface name.