#include "pch.h" #include "NetWorkUtil.h" #include #include #include using namespace std; #pragma comment(lib,"wsock32.lib") int NetWorkUtil::get_localhost_ip(char* buff) { struct hostent* ph = 0; WSADATA w; WSAStartup(0x0101, &w);//ÕâÒ»ÐбØÐëÔÚʹÓÃÈκÎSOCKETº¯Êýǰд£¡ gethostname(buff, 256); string hostNmae = buff;//´Ë´¦»ñµÃ±¾»úÃû³Æ ph = gethostbyname(buff); const char* IP = inet_ntoa(*((struct in_addr*)ph->h_addr_list[0]));//´Ë´¦»ñµÃ±¾»úIP WSACleanup(); return 0; }