From ba01adb3542653ed45199c624d4e18275a35ff78 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 22 Jan 2018 02:16:16 -0800 Subject: [PATCH] client: fix BSD build (from Larry Rosenman) --- client/hostinfo_unix.cpp | 4 +++- client/mac_address.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/client/hostinfo_unix.cpp b/client/hostinfo_unix.cpp index 76c4aae5c3..7e2b85a433 100644 --- a/client/hostinfo_unix.cpp +++ b/client/hostinfo_unix.cpp @@ -164,7 +164,9 @@ extern "C" { // The following is intended to be true both on Linux // and Debian GNU/kFreeBSD (see trac #521) // -#define LINUX_LIKE_SYSTEM (defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)) && !defined(__HAIKU__) +#if (defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)) && !defined(__HAIKU__) +#define LINUX_LIKE_SYSTEM 1 +#endif // Returns the offset between LOCAL STANDARD TIME and UTC. // LOCAL_STANDARD_TIME = UTC_TIME + get_timezone(). diff --git a/client/mac_address.cpp b/client/mac_address.cpp index e08a25ae8b..42ef2b760b 100644 --- a/client/mac_address.cpp +++ b/client/mac_address.cpp @@ -67,6 +67,10 @@ #ifdef HAVE_NETINET_ETHER_H #include #endif +#if defined(__FreeBSD__) +#include +#include +#endif #include "mac_address.h" @@ -262,10 +266,32 @@ int get_mac_address(char* address) { return -1; } hw_addr = (struct ether_addr *)&(item->lifr_lifru.lifru_enaddr); +#elif defined(__FreeBSD__) + struct ifaddrs *ifap, *ifaptr; + unsigned char *ptr; + + if (getifaddrs(&ifap) == 0) { + for(ifaptr = ifap; ifaptr != NULL; ifaptr = (ifaptr)->ifa_next) { + if (!strcmp((ifaptr)->ifa_name, item->ifr_name) && (((ifaptr)->ifa_addr)->sa_family == AF_LINK)) { + ptr = (unsigned char *)LLADDR((struct sockaddr_dl *)(ifaptr)->ifa_addr); + hw_addr = (struct ether_addr *)ptr; + break; + } + } + } else { + return -1; + } +#else + return -1; #endif strcpy(address, ether_ntoa(hw_addr)); +#if defined(__FreeBSD__) + freeifaddrs(ifap); +#endif #ifdef HAVE_STRUCT_LIFCONF if (strstr(item->lifr_name, "eth")) break; +#elif defined(__FreeBSD__) + break; #else if (strstr(item->ifr_name, "eth")) break; #endif