#include <iostream.h>
#include <winsock.h>
struct hostent *phe;
//----------------------------------------------------------
String GetLocalIP(int ipnum)
{
WSAData wsaData;
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0)
{
return "255";
}
//int retval = doit(argc, argv);
char ac[80];
if (gethostname(ac, sizeof(ac)) == SOCKET_ERROR)
{
//return WSAGetLastError();
}
//return ac;
/* attempts to find host */
phe = gethostbyname(ac);
if (phe == 0)
{
return "error";
}
/* Return specified local IP address */
for (int i = 0; phe->h_addr_list != 0; ++i)
{
struct in_addr addr;
memcpy(&addr, phe->h_addr_list, sizeof(struct in_addr));
//cout << "Address " << i << ": " << inet_ntoa(addr) << endl;
/* returns specified IP */
if (i == ipnum)
return inet_ntoa(addr);
}
WSACleanup();
return "Done";
}
//---------------------------------------------------------- Cyprus