util.hpp (3becda7020c72437fe1d1b2aeb44ba65e736f2cb) util.hpp (01c816f25b391435213421825413ada89d1ffd15)
1#pragma once
2#include "types.hpp"
3
4#include <net/ethernet.h>
5#include <netinet/in.h>
6#include <unistd.h>
7
8#include <cstring>
9#include <filesystem>
10#include <optional>
11#include <sdbusplus/bus.hpp>
1#pragma once
2#include "types.hpp"
3
4#include <net/ethernet.h>
5#include <netinet/in.h>
6#include <unistd.h>
7
8#include <cstring>
9#include <filesystem>
10#include <optional>
11#include <sdbusplus/bus.hpp>
12#include <stdplus/raw.hpp>
12#include <stdplus/zstring.hpp>
13#include <string>
14#include <string_view>
15#include <unordered_set>
16#include <xyz/openbmc_project/Network/EthernetInterface/server.hpp>
17
18namespace phosphor
19{

--- 31 unchanged lines hidden (view full) ---

51/** @brief Determines if the mac address is a unicast address
52 * @param[in] mac - The mac address
53 * @return True if not multicast or empty
54 */
55bool isUnicast(const ether_addr& mac);
56
57} // namespace mac_address
58
13#include <stdplus/zstring.hpp>
14#include <string>
15#include <string_view>
16#include <unordered_set>
17#include <xyz/openbmc_project/Network/EthernetInterface/server.hpp>
18
19namespace phosphor
20{

--- 31 unchanged lines hidden (view full) ---

52/** @brief Determines if the mac address is a unicast address
53 * @param[in] mac - The mac address
54 * @return True if not multicast or empty
55 */
56bool isUnicast(const ether_addr& mac);
57
58} // namespace mac_address
59
59template <int family>
60struct FamilyTraits
61{
62};
63
64template <>
65struct FamilyTraits<AF_INET>
66{
67 using addr = in_addr;
68};
69
70template <>
71struct FamilyTraits<AF_INET6>
72{
73 using addr = in6_addr;
74};
75
76/* @brief converts a sockaddr for the specified address family into
77 * a type_safe InAddrAny.
78 * @param[in] family - The address family of the buf
79 * @param[in] buf - The network byte order address
80 */
60/* @brief converts a sockaddr for the specified address family into
61 * a type_safe InAddrAny.
62 * @param[in] family - The address family of the buf
63 * @param[in] buf - The network byte order address
64 */
81template <int family>
82typename FamilyTraits<family>::addr addrFromBuf(std::string_view buf);
83InAddrAny addrFromBuf(int family, std::string_view buf);
65constexpr InAddrAny addrFromBuf(int family, std::string_view buf)
66{
67 switch (family)
68 {
69 case AF_INET:
70 return stdplus::raw::copyFromStrict<in_addr>(buf);
71 case AF_INET6:
72 return stdplus::raw::copyFromStrict<in6_addr>(buf);
73 }
74 throw std::invalid_argument("Unrecognized family");
75}
84
85/** @brief Delete the given interface.
86 * @param[in] intf - interface name.
87 */
88void deleteInterface(stdplus::const_zstring intf);
89
90/** @brief Converts the interface name into a u-boot environment
91 * variable that would hold its ethernet address.

--- 64 unchanged lines hidden ---
76
77/** @brief Delete the given interface.
78 * @param[in] intf - interface name.
79 */
80void deleteInterface(stdplus::const_zstring intf);
81
82/** @brief Converts the interface name into a u-boot environment
83 * variable that would hold its ethernet address.

--- 64 unchanged lines hidden ---