Chinaunix首页 | 论坛 | 博客

分类: LINUX

2011-10-13 16:12:42

  1. 接着处理:/src/host.c

  2. 663 struct address_list *;=============>
  3. 664 lookup_host (const char *host, int flags)
  4. 665 {
  5. 677   {
  6. 678     uint32_t addr_ipv4 = (uint32_t)inet_addr (host);1、________--------->
  7. 679     if (addr_ipv4 != (uint32_t) -1)  /*如果返回成功*/
  8. 680       {
  9. 681         /* No need to cache host->addr relation, just return the
  10. 682            address.  */
  11. 683         char *vec[2];
  12. 684         vec[0] = (char *)&addr_ipv4;
  13. 685         vec[1] = NULL;
  14. 686         return address_list_from_ipv4_addresses (vec);2、_______--------->
  15. 687       }
  16. 688   }
  17.    /*ipv6的不分析了*/
  18. 713   if (use_cache)  /*如果用cache的主机名,并且LH_REFRECH不为1*/
  19. 714     {
  20. 715       if (!(flags & LH_REFRESH))
  21. 716         {
  22. 717           al = cache_query (host);  /*这是在hash_table中查这个主机的名字,前面说过将名字相同的存储到一个链表中*/
  23. 718           if (al)
  24. 719             return al; /*返回这个地址*/
  25. 720         }
  26. 721       else
  27. 722         cache_remove (host); /*否则,就删除这个host名*/
  28. 723     }
复制代码
  1. =============>
  2. 77 struct address_list {
  3. 78   int count;                    /* number of adrresses ,地址的个数*/
  4. 79   ip_address *addresses;        /* pointer to the string of addresses指向地址类型的字符串 */
  5. 80
  6. 81   int faulty;                   /* number of addresses known not to work. 不工作的地址*/
  7. 82   bool connected;               /* whether we were able to connect to
  8. 83                                    one of the addresses in the list,
  9. 84                                    at least once. 是否能够连接表中的地址*/
  10. 85
  11. 86   int refcount;                 /* reference count; when it drops to
  12. 87                                    0, the entry is freed. 引用此地址的计数,当到0时,就释放了*/
  13. 88 };
复制代码
  1. 1、_________----------->
  2. The inet_addr() function converts the Internet host address cp from numbers-and-dots notation into binary data in network byte order. If the input is invalid, INADDR_NONE (usually -1) is returned. This is an obsolete interface to inet_aton(), described immediately above; it is obsolete because -1 is a valid address (255.255.255.255), and inet_aton() provides a cleaner way to indicate error return
  3. /*函数将无符号整数网络地址转化成二进制网络字序,如果输入无效返回-1返回。*/
  4. 2、_______---------->
复制代码
  1. 262 static struct address_list *
  2. 263 address_list_from_ipv4_addresses (char **vec)
  3. 264 {
  4. 265   int count, i;
  5. 266   struct address_list *al = xnew0 (struct address_list); /*建立一个address_list结构*/
  6. 267
  7. 268   count = 0;
  8. 269   while (vec[count])  
  9. 270     ++count;
  10. 271   assert (count > 0);
  11. 272
  12. 273   al->addresses = xnew_array (ip_address, count);  /*建立count个ip_address地址*/
  13. 274   al->count     = count;
  14. 275   al->refcount  = 1;
  15. 276
  16. 277   for (i = 0; i < count; i++)
  17. 278     {
  18. 279       ip_address *ip = &al->addresses[i]; /*给指针一个指向的地址==========>*/
  19. 280       ip->family = AF_INET;  /*所在域是AF_INET*/
  20. 281       memcpy (IP_INADDR_DATA (ip), vec[i], 4);  /*将地址赋值过去ip地址为4个字节*/
  21. 282     }
  22. 283
  23. 284   return al;  /*返回al这个里面包含了很多ip信息*/

  24. }
复制代码

  1. =================>
  2. 55 typedef struct {
  3. 56   
  4. 57   int family;
  5. 58     
  6. 60   union {
  7. 61     struct in_addr d4;          /* IPv4 address 这就是ip地址 */
  8. 62 #ifdef ENABLE_IPV6
  9. 63     struct in6_addr d6;         /* IPv6 address */
  10. 64 #endif
  11. 65   } data;

阅读(1332) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~