#include "InitSock.h"
#include <stdio.h>
void main()
{
CInitSock initSock;
char szHost[256] = {0};
::gethostname(szHost, 256);
hostent* pHost = ::gethostbyname(szHost);
//in_addr是表示IP地址的结构
in_addr addr;
for (int i=0;;i++)
{
char* p = pHost->h_addr_list[i];
if (p == NULL)
{
break;
}
memcpy(&addr.S_un.S_addr, p, pHost->h_length);
char* szIP = ::inet_ntoa(addr);
printf("本机IP地址为:%s\n", szIP);
}
printf("*******************************");
getchar();
}
打印结果: