types: Migrate to stdplus EtherAddr

Change-Id: I1ec2cd0b57a9f02fe96bbe9a068d1a437805b43a
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/types.hpp b/src/types.hpp
index 53a3c89..f7c0fa3 100644
--- a/src/types.hpp
+++ b/src/types.hpp
@@ -1,8 +1,9 @@
 #pragma once
 #include <fmt/core.h>
-#include <net/ethernet.h>
 #include <netinet/in.h>
 
+#include <stdplus/net/addr/ether.hpp>
+
 #include <algorithm>
 #include <array>
 #include <numeric>
@@ -14,12 +15,6 @@
 #include <unordered_set>
 #include <variant>
 
-constexpr bool operator==(ether_addr lhs, ether_addr rhs) noexcept
-{
-    return std::equal(lhs.ether_addr_octet, lhs.ether_addr_octet + 6,
-                      rhs.ether_addr_octet);
-}
-
 constexpr bool operator==(in_addr lhs, in_addr rhs) noexcept
 {
     return lhs.s_addr == rhs.s_addr;
@@ -85,7 +80,7 @@
     unsigned idx;
     unsigned flags;
     std::optional<std::string> name = std::nullopt;
-    std::optional<ether_addr> mac = std::nullopt;
+    std::optional<stdplus::EtherAddr> mac = std::nullopt;
     std::optional<unsigned> mtu = std::nullopt;
     std::optional<unsigned> parent_idx = std::nullopt;
     std::optional<std::string> kind = std::nullopt;
@@ -125,7 +120,7 @@
     unsigned ifidx;
     uint16_t state;
     std::optional<InAddrAny> addr;
-    std::optional<ether_addr> mac;
+    std::optional<stdplus::EtherAddr> mac;
 
     constexpr bool operator==(const NeighborInfo& rhs) const noexcept
     {
@@ -356,38 +351,6 @@
 {};
 
 template <>
-struct ToAddr<ether_addr>
-{
-    constexpr ether_addr operator()(std::string_view str) const
-    {
-        constexpr DecodeInt<uint8_t, 16> di;
-        ether_addr ret;
-        if (str.size() == 12 && str.find(":") == str.npos)
-        {
-            for (size_t i = 0; i < 6; ++i)
-            {
-                ret.ether_addr_octet[i] = di(str.substr(i * 2, 2));
-            }
-        }
-        else
-        {
-            for (size_t i = 0; i < 5; ++i)
-            {
-                auto loc = str.find(":");
-                ret.ether_addr_octet[i] = di(str.substr(0, loc));
-                str.remove_prefix(loc == str.npos ? str.size() : loc + 1);
-                if (str.empty())
-                {
-                    throw std::invalid_argument("Missing mac data");
-                }
-            }
-            ret.ether_addr_octet[5] = di(str);
-        }
-        return ret;
-    }
-};
-
-template <>
 struct ToAddr<in_addr>
 {
     constexpr in_addr operator()(std::string_view str) const
@@ -516,29 +479,6 @@
 };
 
 template <>
-struct ToStr<ether_addr>
-{
-    // 6 octets * 2 hex chars + 5 separators
-    static constexpr uint8_t buf_size = 17;
-    using buf_type = std::array<char, buf_size>;
-
-    constexpr char* operator()(char* buf, ether_addr v) const noexcept
-    {
-        for (char* ptr = buf + 2; ptr < buf + buf_size; ptr += 3)
-        {
-            *ptr = ':';
-        }
-        for (size_t i = 0; i < 6; ++i)
-        {
-            char* tmp = buf + i * 3;
-            uint8_t byte = v.ether_addr_octet[i];
-            EncodeInt<uint8_t, 16>{}(tmp, byte, 2);
-        }
-        return buf + buf_size;
-    }
-};
-
-template <>
 struct ToStr<in_addr>
 {
     // 4 octets * 3 dec chars + 3 separators
@@ -742,9 +682,6 @@
 namespace fmt
 {
 template <>
-struct formatter<ether_addr> : phosphor::network::detail::Format<ether_addr>
-{};
-template <>
 struct formatter<in_addr> : phosphor::network::detail::Format<in_addr>
 {};
 template <>
@@ -762,7 +699,6 @@
 
 namespace std
 {
-string to_string(ether_addr value);
 string to_string(in_addr value);
 string to_string(in6_addr value);
 string to_string(phosphor::network::InAddrAny value);
@@ -777,11 +713,6 @@
     return phosphor::network::detail::veq(rhs, lhs);
 }
 
-auto& operator<<(auto& os, ether_addr v)
-{
-    return os << phosphor::network::detail::ToStrBuf<ether_addr>{}(v);
-}
-
 auto& operator<<(auto& os, in_addr v)
 {
     return os << phosphor::network::detail::ToStrBuf<in_addr>{}(v);