1 #include <sys/socket.h>
4 #define AF_LOWLEVEL AF_LINK
6 #include <linux/if_packet.h>
7 #define AF_LOWLEVEL AF_PACKET
29 typedef std::vector<unsigned>
tmac;
33 struct ifaddrs *ifap, *ifaptr;
37 if (getifaddrs(&ifap) == 0) {
38 for(ifaptr = ifap; ifaptr != NULL; ifaptr = (ifaptr)->ifa_next) {
40 if ( ! (ifaptr->ifa_flags & IFF_LOOPBACK) &&
41 ! (ifaptr->ifa_flags & IFF_POINTOPOINT) ) {
44 if (((ifaptr)->ifa_addr)->sa_family ==
AF_LOWLEVEL && strncmp(
"awdl",(ifaptr)->ifa_name,4)) {
46 ptr = (
unsigned char *)LLADDR((
struct sockaddr_dl *)(ifaptr)->ifa_addr);
48 ptr = (
unsigned char *)(((
struct sockaddr_ll*)ifaptr->ifa_addr)->sll_addr);
50 macs.insert(
tmac({*ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)}));
61 tmac comb = accumulate( macs.begin( ),macs.end( ),
tmac({ 0,0,0,0,0,0 }),
63 tmac result(acc.size());
64 std::transform(acc.begin(), acc.end(), mac.begin(), result.begin(), std::plus<int>());
74 std::stringstream sstream;
75 sstream << std::hex << comb[0] << comb[1] << comb[2] << comb[3] << comb[4] << comb[5];
76 std::string hash = sstream.str();
std::string getUniqueId()
std::vector< unsigned > tmac
transform(a.begin(), a.end(), std::ostream_iterator< int >(cout,"\n"), compose(unary(h), compose(unary(f), unary(f))))
Global Functions.