- #include <Windows.h>
- #include <Iphlpapi.h>
- // Get a unique identifier - really a MAC address for the ethernet adapter. There might be more than one, just use the last one.
- // Shamelessly ripped from here: https://stackoverflow.com/questions/13646621/how-to-get-mac-address-in-windows-with-c
- void identify() {
- PIP_ADAPTER_INFO AdapterInfo;
- DWORD dwBufLen = sizeof(IP_ADAPTER_INFO);
- char mac_addr[19];
- AdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
- if (AdapterInfo == NULL) {
- hkDrawText("Error allocating memory needed to call GetAdaptersinfo", C_TEXT_RED);
- return;
- }
- // Make an initial call to GetAdaptersInfo to get the necessary size into the dwBufLen variable
- if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == ERROR_BUFFER_OVERFLOW) {
- free(AdapterInfo);
- AdapterInfo = (IP_ADAPTER_INFO *)malloc(dwBufLen);
- if (AdapterInfo == NULL) {
- hkDrawText("Error allocating memory needed to call GetAdaptersinfo", C_TEXT_RED);
- return;
- }
- }
- if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == NO_ERROR) {
- // Contains pointer to current adapter info
- PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
- do {
- // technically should look at pAdapterInfo->AddressLength
- // and not assume it is 6.
- sprintf(mac_addr, "%02X:%02X:%02X:%02X:%02X:%02X",
- pAdapterInfo->Address[0], pAdapterInfo->Address[1],
- pAdapterInfo->Address[2], pAdapterInfo->Address[3],
- pAdapterInfo->Address[4], pAdapterInfo->Address[5]);
- //hkDrawPrintf(PREF_DEBUG, C_TEXT_RED, "Address: %s, mac: %s", pAdapterInfo->IpAddressList.IpAddress.String, mac_addr);
- strcpy_s(hac2_id, mac_addr);
- pAdapterInfo = pAdapterInfo->Next;
- } while (pAdapterInfo);
- }
- free(AdapterInfo);
- return;
- }
Recent Pastes