tags:

views:

280

answers:

2

As the title says, I've been trying to achieve that for the better part of the day. Any help would be apreciated.

+3  A: 

This code should work:

{
 ULONG outBufLen = 0;
 DWORD dwRetVal = 0;
 IP_ADAPTER_INFO* pAdapterInfos = (IP_ADAPTER_INFO*) malloc(sizeof(IP_ADAPTER_INFO));

 // retry up to 5 times, to get the adapter infos needed
 for( int i = 0; i < 5 && (dwRetVal == ERROR_BUFFER_OVERFLOW || dwRetVal == NO_ERROR); ++i )
 {
  dwRetVal = GetAdaptersInfo(pAdapterInfos, &outBufLen);
  if( dwRetVal == NO_ERROR )
  {
   break;
  }
  else if( dwRetVal == ERROR_BUFFER_OVERFLOW )
  {
   free(pAdapterInfos);
   pAdapterInfos = (IP_ADAPTER_INFO*) malloc(outBufLen);
  }
  else
  {
   pAdapterInfos = 0;
   break;
  }
 }
 if( dwRetVal == NO_ERROR )
 {
  IP_ADAPTER_INFO* pAdapterInfo = pAdapterInfos;
  while( pAdapterInfo )
  {
   IP_ADDR_STRING* pIpAddress = &(pAdapterInfo->IpAddressList);
   while( pIpAddress != 0 )
   {
                          // 
                          // <<<<
                          // here pAdapterInfo->Address should contain the MAC address
                          // >>>>
                          // 

    pIpAddress = pIpAddress->Next;
   }
   pAdapterInfo = pAdapterInfo->Next;
  }
 }
 free(pAdapterInfos);
 return false;
}
Christopher
+2  A: 

you only need to master the IPhelper API... this is a link to get you started, with examples doing just what you need.

Adrien Plisson