34 #include <netinet/in.h>
36 #include <sys/ioctl.h>
45 return "00:00:00:00:00:00";
53 fd = socket(AF_INET, SOCK_DGRAM, 0);
54 ifr.ifr_addr.sa_family = AF_INET;
55 strncpy(ifr.ifr_name,
"eth0", IFNAMSIZ - 1);
58 ioctl(fd, SIOCGIFHWADDR, &ifr);
64 printf(
"No ethernet adapter found. Using dummy MAC\n");
65 mac =
"00:00:00:00:00:00";
70 sprintf(temp,
"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
71 (
unsigned char)ifr.ifr_hwaddr.sa_data[0],
72 (
unsigned char)ifr.ifr_hwaddr.sa_data[1],
73 (
unsigned char)ifr.ifr_hwaddr.sa_data[2],
74 (
unsigned char)ifr.ifr_hwaddr.sa_data[3],
75 (
unsigned char)ifr.ifr_hwaddr.sa_data[4],
76 (
unsigned char)ifr.ifr_hwaddr.sa_data[5]);
100 IP_ADAPTER_INFO AdapterInfo[128];
101 DWORD dwBufLen =
sizeof(AdapterInfo);
102 DWORD dwStatus = GetAdaptersInfo(AdapterInfo, &dwBufLen);
105 if (dwStatus != ERROR_SUCCESS)
107 return "00:00:00:00:00:00";
110 PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
115 if (pAdapterInfo->Type == MIB_IF_TYPE_ETHERNET)
117 sprintf_s(szBuffer,
sizeof(szBuffer),
"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
118 pAdapterInfo->Address[0],
119 pAdapterInfo->Address[1],
120 pAdapterInfo->Address[2],
121 pAdapterInfo->Address[3],
122 pAdapterInfo->Address[4],
123 pAdapterInfo->Address[5]);
129 pAdapterInfo = pAdapterInfo->Next;
132 return "00:00:00:00:00:00";