Determining IP Address of a Windows Mobile device

Code to determine IP addresses of adapters on a Windows Mobile device, using IPHelper APIs.

Add Iphlpapi.lib to linker settings.

#include “Iphlpapi.h”

PIP_ADAPTER_INFO pinfo = NULL;
ULONG OutBufLen = 0;
DWORD dwRet = GetAdaptersInfo(NULL, &OutBufLen);
if (dwRet == ERROR_BUFFER_OVERFLOW)
{
pinfo = (PIP_ADAPTER_INFO)malloc(OutBufLen);
dwRet = GetAdaptersInfo(pinfo,&OutBufLen);
while (pinfo != NULL)
{
if (dwRet==ERROR_SUCCESS)
{
PIP_ADDR_STRING pAddressList = &(pinfo->IpAddressList);
do
{
printf(pAddressList->IpAddress.String);
pAddressList = pAddressList->Next;
} while (pAddressList != NULL);
}
pinfo = pinfo->Next;
}
free(pinfo);
}

Leave a Comment