深度剖析WinPcap之(七)――获得与释放网络适配器设备列表(3)

1.3.3      pcap_freealldevs函数

函数pcap_freealldevs()释放 由函数pcap_findalldevs_ex()或pcap_findalldevs()返回的网络接口链表,函数参数 alldevs为所需释放链表。
函数的主要代码如下:
void pcap_freealldevs(pcap_if_t *alldevs)
{
     pcap_if_t *curdev, *nextdev;
     pcap_addr_t *curaddr, *nextaddr;
 
    /*遍历链表,释放各节点所占用的资源*/
     for (curdev = alldevs; curdev != NULL; curdev = nextdev) {
         nextdev = curdev->next;
 
         // 释放所有的地址所占的内存资源
         for (curaddr = curdev->addresses; curaddr != NULL; curaddr = nextaddr) {
              nextaddr = curaddr->next;
              if (curaddr->addr)
                   free(curaddr->addr);
              if (curaddr->netmask)
                   free(curaddr->netmask);
              if (curaddr->broadaddr)
                   free(curaddr->broadaddr);
              if (curaddr->dstaddr)
                   free(curaddr->dstaddr);
              free(curaddr);
         }
 
         //释放接口的名字所占的内存资源
         free(curdev->name);
 
//释放接口的描述所占的内存资源   
         if (curdev->description != NULL)
              free(curdev->description);
 
           //释放该接口     
         free(curdev);
     }
}
 

你可能感兴趣的:(职场,休闲,winpcap)