获得本地主机名和ip地址
bool getIPAddress(char * outIP, char * outHost)
{
char name[255];
if (gethostname(name, sizeof(name)) == 0)
{
if (outHost != NULL)
strcpy(outHost, name);
PHOSTENT hostinfo;
if((hostinfo = gethostbyname(name)) != NULL)
{
LPCSTR pIP = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
if (outIP != NULL)
strcpy(outIP, pIP);
return true;
}
}
return false;
}