- 论坛徽章:
- 0
|
- int GetLocalIP(char *LocaIP)
- {
- // gethostname
- WORD wVersionRequested;
- WSADATA wsaPata;
- char localhost[64] = {0};
- wVersionRequested = MAKEWORD(2,0);
- WSAStartup(wVersionRequested, &wsaPata);
- gethostname(localhost, 64);
- //AfxMessageBox(localhost);
- //gethostbyname
- struct hostent *hptr;
- struct in_addr addr;
-
- hptr = gethostbyname(localhost);
- addr.s_addr = *((unsigned int *)*(hptr->h_addr_list));
- sprintf(LocaIP, "%s", inet_ntoa(addr));
- //AfxMessageBox(LocaIP);
-
- WSACleanup();
- return 0;
- }
复制代码 VS2010 , WIN7 获取成功. 临时写的, 数组定义可能太大了. 不过将就一下吧. |
|