Gethostbyname 函数介绍

WSADATA wsadata;

 WSAStartup(0x202, &wsadata);

char name[256];

int i;

int I_IpCount;

u_long *I_IpTable;

I_IpCount = 0;

 if (gethostname(name, 256) == 0)

{ struct hostent* hostinfo = gethostbyname(name);

for (i=0; hostinfo->h_addr_list[i]!=NULL; i++)

 { I_IpCount ++; }

 I_IpTable = (u_long*)malloc(sizeof(u_long)*I_IpCount);

for (i=0; hostinfo->h_addr_list[i]!=NULL; i++)

 { I_IpTable[i] = (u_long)htonl(((struct in_addr*)hostinfo->h_addr_list[i])->s_addr); } }

WSACleanup();

 

编译器:VS6.0OS:XP2在stdafx.h增加:#include #pragma comment(lib,"ws2_32.lib")

 

你可能感兴趣的:(struct,list,XP,OS,null,编译器)