Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1184948
  • 博文数量: 573
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 66
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-28 16:21
文章分类

全部博文(573)

文章存档

2018年(3)

2016年(48)

2015年(522)

分类: LINUX

2015-12-02 15:36:45


点击(此处)折叠或打开

  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <netdb.h>

  5. int main(int argc, char * * argv)
  6. {
  7.     printf("sethostent函数执行:\n");
  8.     sethostent(1);
  9.     printf("-1.-1**************************************\n");
  10.     struct hostent * host = NULL;
  11.     host = gethostent();
  12.     printf("h_name =[%s]\n", host->h_name);
  13.     printf("*h_aliases =[%s]\n", *(host->h_aliases));
  14.     printf("h_addrtype =[%d]\n", host->h_addrtype);
  15.     printf("h_length =[%d]\n", host->h_length);
  16.     printf("h_addr_list =[%s]\n", host->h_addr_list[0]);
  17.     printf("h_addr =[%s]\n", host->h_addr);
  18.     
  19.     struct sockaddr_in sin;
  20.     bzero(&sin, sizeof(sin));
  21.     bcopy(host->h_addr, &sin.sin_addr, host->h_length);
  22.     char ipbuf[128];
  23.     memset(ipbuf, 0, sizeof(ipbuf));
  24.     inet_ntop(AF_INET, &sin.sin_addr.s_addr, ipbuf, sizeof(ipbuf));
  25.     printf("主机名=[%s],IP地址=[%s]\n",host->h_name,ipbuf);
  26.     
  27.     bzero(&sin, sizeof(sin));
  28.     memcpy(&sin.sin_addr, host->h_addr, host->h_length);
  29.     memset(ipbuf, 0, sizeof(ipbuf));
  30.     inet_ntop(AF_INET, &sin.sin_addr.s_addr, ipbuf, sizeof(ipbuf));
  31.     printf("主机名=[%s],IP地址=[%s]\n",host->h_name,ipbuf);
  32.     
  33.     printf("000**************************************\n");
  34.     struct hostent * host0 = NULL;
  35.     host0 = gethostent();
  36.     printf("h_name =[%s]\n", host0->h_name);
  37.     printf("*h_aliases =[%s]\n", *(host0->h_aliases));
  38.     printf("h_addrtype =[%d]\n", host0->h_addrtype);
  39.     printf("h_length =[%d]\n", host0->h_length);
  40.     printf("h_addr_list =[%s]\n", host->h_addr_list);
  41.     printf("*h_addr_list=[%s]\n", *(host->h_addr_list));
  42.     printf("h_addr_list[0]=[%s]\n", (host->h_addr_list)[0]);
  43.     printf("h_addr_list[1]=[%s]\n", (host->h_addr_list)[1]);
  44.     /*
  45.     printf("h_addr_list[2]=[%s]\n", (host->h_addr_list)[2]);
  46.     printf("h_addr_list[3]=[%s]\n", (host->h_addr_list)[3]);
  47.     printf("h_addr_list[4]=[%s]\n", (host->h_addr_list)[4]);
  48.     */
  49.     
  50.     printf("111**************************************\n");
  51.     struct hostent * host1 = NULL;
  52.     host1 = gethostent();
  53.     printf("h_name =[%s]\n", host1->h_name);
  54.     printf("*h_aliases =[%s]\n", *(host1->h_aliases));
  55.     printf("h_addrtype =[%d]\n", host1->h_addrtype);
  56.     printf("h_length =[%d]\n", host1->h_length);

  57.     printf("222**************************************\n");
  58.     struct hostent * host2 = NULL;
  59.     host2 = gethostent();
  60.     printf("h_name =[%s]\n", host2->h_name);
  61.     printf("*h_aliases =[%s]\n", *(host2->h_aliases));
  62.     printf("h_addrtype =[%d]\n", host2->h_addrtype);
  63.     printf("h_length =[%d]\n", host2->h_length);

  64.     printf("333**************************************\n");
  65.     /*sethostent(1);*/
  66.     struct hostent * host3 = NULL;
  67.     host3 = gethostent();
  68.     printf("h_name =[%s]\n", host3->h_name);
  69.     printf("*h_aliases =[%s]\n", *(host3->h_aliases));
  70.     printf("h_addrtype =[%d]\n", host3->h_addrtype);
  71.     printf("h_length =[%d]\n", host3->h_length);

  72.     printf("444**************************************\n");
  73.     struct hostent * host4 = NULL;
  74.     host4 = gethostent();
  75.     printf("h_name =[%s]\n", host4->h_name);
  76.     printf("*h_aliases =[%s]\n", *(host4->h_aliases));
  77.     printf("h_addrtype =[%d]\n", host4->h_addrtype);
  78.     printf("h_length =[%d]\n", host4->h_length);
  79.     
  80.     printf("555**************************************\n");
  81.     sethostent(1);
  82.     struct hostent * host5 = NULL;
  83.     host5 = gethostent();
  84.     printf("h_name =[%s]\n", host5->h_name);
  85.     printf("*h_aliases =[%s]\n", *(host5->h_aliases));
  86.     printf("h_addrtype =[%d]\n", host5->h_addrtype);
  87.     printf("h_length =[%d]\n", host5->h_length);

  88.     printf("sethostent函数执行:\n");
  89.     sethostent(1);
  90.     printf("666**************************************\n");
  91.     struct hostent * host6 = NULL;
  92.     host6 = gethostent();
  93.     printf("h_name =[%s]\n", host6->h_name);
  94.     printf("*h_aliases =[%s]\n", *(host6->h_aliases));
  95.     printf("h_addrtype =[%d]\n", host6->h_addrtype);
  96.     printf("h_length =[%d]\n", host6->h_length);
  97.     
  98.     printf("777**************************************\n");
  99.     struct hostent * host7 = NULL;
  100.     host7 = gethostent();
  101.     printf("h_name =[%s]\n", host7->h_name);
  102.     printf("*h_aliases =[%s]\n", *(host7->h_aliases));
  103.     printf("h_addrtype =[%d]\n", host7->h_addrtype);
  104.     printf("h_length =[%d]\n", host7->h_length);
  105.     
  106.     printf("888**************************************\n");
  107.     struct hostent * host8 = NULL;
  108.     host8 = gethostent();
  109.     printf("h_name =[%s]\n", host8->h_name);
  110.     printf("*h_aliases =[%s]\n", *(host8->h_aliases));
  111.     printf("h_addrtype =[%d]\n", host8->h_addrtype);
  112.     printf("h_length =[%d]\n", host8->h_length);
  113.     
  114.     printf("999**************************************\n");
  115.     struct hostent * host9 = NULL;
  116.     host9 = gethostent();
  117.     printf("h_name =[%s]\n", host9->h_name);
  118.     printf("*h_aliases =[%s]\n", *(host9->h_aliases));
  119.     printf("h_addrtype =[%d]\n", host9->h_addrtype);
  120.     printf("h_length =[%d]\n", host9->h_length);
  121.     
  122.         printf("10.10**************************************\n");
  123.     struct hostent * host10 = NULL;
  124.     host10 = gethostent();
  125.     printf("h_name =[%s]\n", host10->h_name);
  126.     printf("*h_aliases =[%s]\n", *(host10->h_aliases));
  127.     printf("h_addrtype =[%d]\n", host10->h_addrtype);
  128.     printf("h_length =[%d]\n", host10->h_length);
  129.     
  130.     printf("11.11**************************************\n");
  131.     struct hostent * host11 = NULL;
  132.     host11 = gethostent();
  133.     printf("h_name =[%s]\n", host11->h_name);
  134.     printf("*h_aliases =[%s]\n", *(host11->h_aliases));
  135.     printf("h_addrtype =[%d]\n", host11->h_addrtype);
  136.     printf("h_length =[%d]\n", host11->h_length);

  137.     printf("12.12**************************************\n");
  138.     struct hostent * host12 = NULL;
  139.     host12 = gethostent();
  140.     printf("h_name =[%s]\n", host12->h_name);
  141.     printf("*h_aliases =[%s]\n", *(host12->h_aliases));
  142.     printf("h_addrtype =[%d]\n", host12->h_addrtype);
  143.     printf("h_length =[%d]\n", host12->h_length);
  144.     
  145.     return 0;
  146. }

阅读(1150) | 评论(0) | 转发(0) |
0

上一篇:getnameinfo函数

下一篇:mmap函数

给主人留下些什么吧!~~