关于第一个问题,包含头文件<conio.h>,
cout<<"要退出本程序吗?Y/N"<<endl;
if((i=_getche())=='y'||i=='Y')
return;
关于第二个问题。
h_addr_list确实包含有多个地址,如果你安装有多个网卡,
具体的提取方法为:
char szHostName[128];
char szT[20];
if( gethostname(szHostName, 128) == 0 )
{
// Get host adresses
struct hostent * pHost; int i;
pHost = gethostbyname(szHostName);
for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )
{
char str[100];
char addr[20];
int j;
str[0]='\0';
LPCSTR psz=inet_ntoa (*(struct in_addr *)pHost->h_addr_list[i]);
printf("NO %d IP Address : %s\n",i+1,psz);
}
}
cout<<"要退出本程序吗?Y/N"<<endl;
if((i=_getche())=='y'||i=='Y')
return;
关于第二个问题。
h_addr_list确实包含有多个地址,如果你安装有多个网卡,
具体的提取方法为:
char szHostName[128];
char szT[20];
if( gethostname(szHostName, 128) == 0 )
{
// Get host adresses
struct hostent * pHost; int i;
pHost = gethostbyname(szHostName);
for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )
{
char str[100];
char addr[20];
int j;
str[0]='\0';
LPCSTR psz=inet_ntoa (*(struct in_addr *)pHost->h_addr_list[i]);
printf("NO %d IP Address : %s\n",i+1,psz);
}
}
再问一个问题:对于gethostbyaddr()函数,为什么我只能输入本机ip地址有用,输入其他ip地址就不行?