#include <stdio.h>
#include <string.h>
#include <iostream>
#include<netdb.h>
#include<sys/types.h>
#include<netinet/in.h>
//C++要求函数在使用前必须先有声明。这样可以在编译时找到更多的错误。
#include <arpa/inet.h> // inet_ntoa
using namespace std;
int main(void)
{
cout<<"ni hao"<<endl;
struct hostent *h;
char ** aliases;
char **addes;
char str[30];
char host[100];
gethostname(host,100);
if((h=gethostbyname(host))==NULL)
{
cout<<"incorrect exit"<<endl;
}
cout<<"Host name:"<<h->h_name<<endl;
for(aliases=h->h_aliases;*aliases!=NULL;aliases++)
printf("Aliase name:%s/n",*aliases);
switch(h->h_addrtype)
{
case AF_INET:
#ifdef AF_INET6
case AF_INET6:
#endif
addes=h->h_addr_list;
for( ; *addes != NULL; *addes++ )
cout<<"IP Address:"<<inet_ntoa(*((struct in_addr*)(*addes)))<<endl;
break;
}
return 0;
}