Socket编程中一些惯用到的方法

Socket编程中一些常用到的方法获得本地主机名和ip地址bool getIPAddress(char * outIP, char * outHost){c

Socket编程中一些常用到的方法
获得本地主机名和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;}