portability: add support for Illumos

This still won't work on older Solaris systems, but modern Illumos
at least should build and run now.
This commit is contained in:
Justin Maggard
2014-05-14 17:53:25 -07:00
parent 361bc34f93
commit 34cb08928c
10 changed files with 58 additions and 30 deletions

View File

@ -173,7 +173,7 @@ getsyshwaddr(char *buf, int len)
{
unsigned char mac[6];
int ret = -1;
#if defined(HAVE_GETIFADDRS) && !defined (__linux__)
#if defined(HAVE_GETIFADDRS) && !defined (__linux__) && !defined (__sun__)
struct ifaddrs *ifap, *p;
struct sockaddr_in *addr_in;
uint8_t a;
@ -191,7 +191,7 @@ getsyshwaddr(char *buf, int len)
a = (htonl(addr_in->sin_addr.s_addr) >> 0x18) & 0xFF;
if (a == 127)
continue;
#ifdef __linux__
#if defined(__linux__)
struct ifreq ifr;
int fd;
fd = socket(AF_INET, SOCK_DGRAM, 0);
@ -242,9 +242,15 @@ getsyshwaddr(char *buf, int len)
continue;
if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0)
continue;
#ifdef __sun__
if (MACADDR_IS_ZERO(ifr.ifr_addr.sa_data))
continue;
memcpy(mac, ifr.ifr_addr.sa_data, 6);
#else
if (MACADDR_IS_ZERO(ifr.ifr_hwaddr.sa_data))
continue;
memcpy(mac, ifr.ifr_hwaddr.sa_data, 6);
#endif
ret = 0;
break;
}