Friday, January 22, 2010

Getting the IP Addres of a Win CE running board

The following program will help in Obtaining the IP of a Windows CE running board. Its written in C Language. The same will work with all higher version of Windows as well. If you need the other IPs connected to the network adapter, you can access the content of phe->h_addr_list[i], where i will be incremented for each network adapter.

#include

void getIP()
{
char* g_pcIPAddr;
WSAData wsaData;
WSAStartup(MAKEWORD(1, 1), &wsaData);

char ac[80];
gethostname(ac, sizeof(ac));

struct hostent *phe = gethostbyname(ac);
struct in_addr addr;
memcpy(&addr, phe->h_addr_list[0], sizeof(struct in_addr));

g_pcIPAddr = inet_ntoa(addr);

WSACleanup();

return;
}

No comments: