util.hpp (b7d6a1a70a818783151eaa5092c1e3e2682dfb25) util.hpp (9b2a20d3cfa1131521456b9ebfde7a7bb8b234bb)
1#pragma once
2#include "types.hpp"
3
4#include <stdplus/raw.hpp>
5#include <stdplus/zstring.hpp>
6
7#include <optional>
8#include <string>

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

18class Parser;
19}
20
21/* @brief converts a sockaddr for the specified address family into
22 * a type_safe InAddrAny.
23 * @param[in] family - The address family of the buf
24 * @param[in] buf - The network byte order address
25 */
1#pragma once
2#include "types.hpp"
3
4#include <stdplus/raw.hpp>
5#include <stdplus/zstring.hpp>
6
7#include <optional>
8#include <string>

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

18class Parser;
19}
20
21/* @brief converts a sockaddr for the specified address family into
22 * a type_safe InAddrAny.
23 * @param[in] family - The address family of the buf
24 * @param[in] buf - The network byte order address
25 */
26constexpr InAddrAny addrFromBuf(int family, std::string_view buf)
26constexpr stdplus::InAnyAddr addrFromBuf(int family, std::string_view buf)
27{
28 switch (family)
29 {
30 case AF_INET:
27{
28 switch (family)
29 {
30 case AF_INET:
31 return stdplus::raw::copyFromStrict<in_addr>(buf);
31 return stdplus::raw::copyFromStrict<stdplus::In4Addr>(buf);
32 case AF_INET6:
32 case AF_INET6:
33 return stdplus::raw::copyFromStrict<in6_addr>(buf);
33 return stdplus::raw::copyFromStrict<stdplus::In6Addr>(buf);
34 }
35 throw std::invalid_argument("Unrecognized family");
36}
37
38/** @brief Converts the interface name into a u-boot environment
39 * variable that would hold its ethernet address.
40 *
41 * @param[in] intf - interface name

--- 62 unchanged lines hidden ---
34 }
35 throw std::invalid_argument("Unrecognized family");
36}
37
38/** @brief Converts the interface name into a u-boot environment
39 * variable that would hold its ethernet address.
40 *
41 * @param[in] intf - interface name

--- 62 unchanged lines hidden ---