This is a small example on how you can get the MAC address in C both in Linux and Windows. The example searches in fact the MAC address corresponding to a given IP address and returns it.
/* * mac.cpp * Created on: May 25, 2010 * Author: len */ #ifdef WIN32 #include <stdio.h> #include <Windows.h> #include <Iphlpapi.h> #include <Assert.h> #pragma comment(lib, "iphlpapi.lib") /** * @return the mac address of the interface with the given ip */ char* getMAC(const char *ip){ PIP_ADAPTER_INFO AdapterInfo; DWORD dwBufLen = sizeof(AdapterInfo); char *mac_addr = (char*)malloc(17); AdapterInfo = (IP_ADAPTER_INFO *) malloc(sizeof(IP_ADAPTER_INFO)); if (AdapterInfo == NULL) { printf("Error allocating memory needed to call GetAdaptersinfo\n"); return NULL; } // 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) { printf("Error allocating memory needed to call GetAdaptersinfo\n"); return NULL; } } if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == NO_ERROR) { PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;// Contains pointer to current adapter info do { 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]); printf("Address: %s, mac: %s", pAdapterInfo->IpAddressList....