13 #ifndef __STOUT_POSIX_MAC_HPP__ 14 #define __STOUT_POSIX_MAC_HPP__ 18 #include <sys/types.h> 35 struct ifaddrs* ifaddr =
nullptr;
36 if (getifaddrs(&ifaddr) == -1) {
43 for (
struct ifaddrs* ifa = ifaddr; ifa !=
nullptr; ifa = ifa->ifa_next) {
44 if (ifa->ifa_name !=
nullptr && !strcmp(ifa->ifa_name, name.c_str())) {
47 # if defined(__linux__) 48 if (ifa->ifa_addr !=
nullptr && ifa->ifa_addr->sa_family == AF_PACKET) {
49 struct sockaddr_ll* link = (
struct sockaddr_ll*) ifa->ifa_addr;
51 if (link->sll_halen == 6) {
52 struct ether_addr* addr = (
struct ether_addr*) link->sll_addr;
53 MAC mac(addr->ether_addr_octet);
65 # elif defined(__APPLE__) 66 if (ifa->ifa_addr !=
nullptr && ifa->ifa_addr->sa_family == AF_LINK) {
67 struct sockaddr_dl* link = (
struct sockaddr_dl*) ifa->ifa_addr;
69 if (link->sdl_type == IFT_ETHER && link->sdl_alen == 6) {
70 struct ether_addr* addr = (
struct ether_addr*) LLADDR(link);
84 return Error(
"Cannot find the link device");
92 #endif // __STOUT_POSIX_MAC_HPP__ Definition: errorbase.hpp:36
Definition: errorbase.hpp:50
Result< MAC > mac(const std::string &name)
Definition: mac.hpp:33
std::string stringify(int flags)
constexpr const char * name
Definition: shell.hpp:41