首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2012-12-18 
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;}

热点排行