Share via


Listing Addresses (Windows Embedded CE 6.0)

1/6/2010

In the case where an IP Helper function returns a list of adapters, addresses, statistics, and so on, step through the linked list to retrieve the information present.

// Get Adapters Info
PIP_ADAPTER_INFO  pAdapterInfo = NULL;
PIP_ADAPTER_INFO  pOriginalPtr;
ULONG             ulSizeAdapterInfo = 0;
DWORD             dwStatus;

// Find out how big our buffer needs to be to hold the data
dwStatus = GetAdaptersInfo(pAdapterInfo, &ulSizeAdapterInfo);
if (dwStatus == ERROR_BUFFER_OVERFLOW) {
   // Allocate a buffer of the appropriate size
   if (!(pAdapterInfo = (PIP_ADAPTER_INFO)malloc(ulSizeAdapterInfo))) {
      printf("\n Insufficient Memory ");
      return(1);
   }

   // Obtain the Adapter Info
   dwStatus = GetAdaptersInfo(pAdapterInfo, &ulSizeAdapterInfo);
}
   
if (dwStatus != ERROR_SUCCESS) {
   return(1);
}

pOriginalPtr = pAdapterInfo;

if (pAdapterInfo == NULL)
   printf("\n No Interfaces Present.\n");
   // Step through the adapter list
   while (pAdapterInfo != NULL) {

      // Print the Ip Addresses
      printf(" \n\n\t IpAddressList:: ");
      PIP_ADDR_STRING pAddressList = &(pAdapterInfo->IpAddressList);

      do {
         printf("\n\t IpAddress = %hs", pAddressList->IpAddress.String);
         pAddressList = pAddressList->Next;
      } while (pAddressList != NULL);

// And so on with other members of the Adapter info structure...

      pAdapterInfo = pAdapterInfo->Next;
   } //  while(pAdapterInfo!=NULL){
}

See Also

Concepts

IP Helper Code Samples