macaddr: Add some code for FreeBSD (it should work on the others too)

There doesn't seem to be a way to share this code with Linux as
it doesn't have the sockaddr_dl concept inside the getifaddrs.

I manually verified this on a FreeBSD10 box and hex decoding gave
me the correct mac address and rc was 0.
diff --git a/src/macaddr.c b/src/macaddr.c
index 392ee13..f6b1ebb 100644
--- a/src/macaddr.c
+++ b/src/macaddr.c
@@ -25,6 +25,46 @@
 	return 0;
 }
 
+#if defined(__FreeBSD__)
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <ifaddrs.h>
+#include <net/if_dl.h>
+#include <net/if_types.h>
+
+
+int osmo_get_macaddr(uint8_t *mac_out, const char *dev_name)
+{
+	int rc = -1;
+	struct ifaddrs *ifa, *ifaddr;
+
+	if (getifaddrs(&ifaddr) != 0)
+		return -1;
+
+	for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+		struct sockaddr_dl *sdl;
+
+		sdl = (struct sockaddr_dl *) ifa->ifa_addr;
+		if (!sdl)
+			continue;
+		if (sdl->sdl_family != AF_LINK)
+			continue;
+		if (sdl->sdl_type != IFT_ETHER)
+			continue;
+		if (strcmp(ifa->ifa_name, dev_name) != 0)
+			continue;
+
+		memcpy(mac_out, LLADDR(sdl), 6);
+		rc = 0;
+		break;
+	}
+
+	freeifaddrs(ifaddr);
+	return 0;
+}
+
+#else
+
 #include <sys/ioctl.h>
 #include <net/if.h>
 #include <netinet/ip.h>
@@ -50,3 +90,4 @@
 
 	return 0;
 }
+#endif