mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Implement MACAddress::findAllAddresses as in MacOSX.
This commit is contained in:
@@ -188,6 +188,8 @@
|
|||||||
|
|
||||||
#if BEAST_BSD
|
#if BEAST_BSD
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <ifaddrs.h>
|
||||||
|
#include <net/if_dl.h>
|
||||||
#include <kvm.h>
|
#include <kvm.h>
|
||||||
#include <langinfo.h>
|
#include <langinfo.h>
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
|||||||
@@ -23,34 +23,28 @@
|
|||||||
|
|
||||||
void MACAddress::findAllAddresses (Array<MACAddress>& result)
|
void MACAddress::findAllAddresses (Array<MACAddress>& result)
|
||||||
{
|
{
|
||||||
#if 1
|
ifaddrs* addrs = nullptr;
|
||||||
bassertfalse; // VFALCO TODO Implement for FreeBSD
|
|
||||||
#else
|
if (getifaddrs (&addrs) == 0)
|
||||||
const int s = socket (AF_INET, SOCK_DGRAM, 0);
|
|
||||||
if (s != -1)
|
|
||||||
{
|
{
|
||||||
char buf [1024];
|
for (const ifaddrs* cursor = addrs; cursor != nullptr; cursor = cursor->ifa_next)
|
||||||
struct ifconf ifc;
|
|
||||||
ifc.ifc_len = sizeof (buf);
|
|
||||||
ifc.ifc_buf = buf;
|
|
||||||
ioctl (s, SIOCGIFCONF, &ifc);
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
|
|
||||||
{
|
{
|
||||||
struct ifreq ifr;
|
sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
|
||||||
strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
|
if (sto->ss_family == AF_LINK)
|
||||||
|
|
||||||
if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
|
|
||||||
&& (ifr.ifr_flags & IFF_LOOPBACK) == 0
|
|
||||||
&& ioctl (s, SIOCGIFHWADDR, &ifr) == 0)
|
|
||||||
{
|
{
|
||||||
result.addIfNotAlreadyThere (MACAddress ((const uint8*) ifr.ifr_hwaddr.sa_data));
|
const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
|
||||||
|
|
||||||
|
#ifndef IFT_ETHER
|
||||||
|
#define IFT_ETHER 6
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (sadd->sdl_type == IFT_ETHER)
|
||||||
|
result.addIfNotAlreadyThere (MACAddress (((const uint8*) sadd->sdl_data) + sadd->sdl_nlen));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close (s);
|
freeifaddrs (addrs);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user