#include <sys/utsname.h>//struct utsname
#include <netdb.h>//struct hostent
#include <stdio.h>//NULL
#include <netinet/in.h>//struct in_addr
//struct utsname
//{
// char sysname[20];//系统名称
// char nodename[20];//本机名
// char release[20];//OS
// char version[20];//OS
// char machine[20];//hardware
//};
int
main()
{
struct utsname un;//
struct hostent h,h1,*hp;
struct in_addr addr;
char **pp;
char hname[200];
gethostname(hname,200);
printf("hostname is %s/n",hname);
if(uname(&un)==-1)
{
return 1;//error
}
if ((hp = gethostbyname(un.nodename))==NULL)
{
return 1;
}
bcopy(hp,&h,sizeof(struct hostent));
if ((hp = gethostbyname("徐盎"))==NULL)
{
return 1;
}
bcopy(hp,&h1,sizeof(struct hostent));
for (pp = h.h_aliases;*pp!=NULL;pp++)
printf("%02X is %s/n",*pp,*pp);
pp = h.h_addr_list;
while(*pp!=NULL)
{
addr.s_addr = *((unsigned int *)*pp);
printf("address is %s/n",inet_ntoa(addr));
pp++;
}
for (pp = h1.h_aliases;*pp!=NULL;pp++)
printf("%02X is %s/n",*pp,*pp);
pp = h1.h_addr_list;
while(*pp!=NULL)
{
addr.s_addr = *((unsigned int *)*pp);
printf("address is %s/n",inet_ntoa(addr));
pp++;
}
printf("the h_addr is %02X/n",h.h_addr);
printf("the h_addr is %02X/n",h1.h_addr);
return 0;//Suc
}