1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| #include "pch.h"
| #include "NetWorkUtil.h"
| #include <windows.h>
| #include <winsock.h>
| #include <string>
| 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;
| }
|
|