[Winpcap-users] after 32 loops pcap_findalldevs() starts returning 0 adapters. Why?

Loris Degioanni loris.degioanni at gmail.com
Thu May 11 15:06:40 GMT 2006


1. Why don't you use the latest version of winpcap, instead of the old 3.0?
2. Don't use pcap_findalldevs() in an infinite loop. It's not its 
purpose, and despite all our efforts even in latest winpcap versions it 
still has some small memory leaks, mostly located inside the MS 
libraries that it calls.

Loris


Test wrote:
> Hi All,
>  
> We are using WinPcap 3.0 to create an application, the problem wwhich we 
> are encountering is after 32 loops pcap_findalldevs() starts returning 0 
> adapters.
>  
> We are simply counting the available adapters after 1/2 seconds . 
> Following is the code which we are using.Kindly advise why after approx 
> 32 loops it starts returning 0 adapters.
>  
> 
> void main()
> 
> {
> 
> int ListCount;
> 
> HANDLE handleArray[12];
> 
> pcap_t *deviceArray[12];
> 
> char errbuffer[PCAP_ERRBUF_SIZE];
> 
> pcap_if_t *allDevs;
> 
> pcap_if_t *D;
> 
> int p=0;
> 
> //FILE *lf;
> 
> //lf = fopen("C:\\Santosh\\Test.txt", "a+");
> 
> //fflush(lf);
> 
> while(1)
> 
> {
> 
> Sleep(500); //Retrieve All Device List
> 
> if (pcap_findalldevs(&allDevs, errbuffer) == -1)
> 
> {
> 
> //If error occurs then Loop back
> 
> continue;
> 
> }
> 
> printf("\n Get List Device %d %s ",p,(allDevs==NULL)?"TRUE":"FALSE");
> 
> //fflush(lf);
> 
> ListCount = 0;
> 
> for(D=allDevs; D; D=D->next)
> 
> {
> 
> if (!(D->flags & PCAP_IF_LOOPBACK))
> 
> {
> 
> //if List of devices is more than 12
> 
> if (ListCount==12)
> 
> continue;
> 
> {
> 
> //Open a device
> 
> if ((deviceArray[ListCount]=pcap_open_live(D->name, 65536, 0, 1000, 
> errbuffer)) == NULL)
> 
> {
> 
> //if device is disabled
> 
> printf("\n Disabled Device %d",ListCount);
> 
> // fflush(lf);
> 
> continue;
> 
> }
> 
> printf("\n Active Device %d",ListCount);
> 
> // fflush(lf);
> 
> //Get event Handle for the Adapter or Device
> 
> handleArray[ListCount++] = pcap_getevent(deviceArray[ListCount]);
> 
> }
> 
> }
> 
> else
> 
> {
> 
> printf("\n Device %s \t%s",D->name,D->description);
> 
> //fflush(lf);
> 
> }
> 
> }
> 
> printf("\nPlease see CurrentADL = %d ", ListCount);
> 
> //fflush(lf);
> 
> for(p=0; p < ListCount; p++)
> 
> {
> 
> CloseHandle(handleArray[p]);
> 
> handleArray[p]=NULL;
> 
> deviceArray[p]=NULL;
> 
> //pcap_close(deviceArray[p]);
> 
> }
> 
> pcap_freealldevs(allDevs);
> 
> }
> 
> }
> 
>  
> 
> santosh
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Winpcap-users mailing list
> Winpcap-users at winpcap.org
> https://www.winpcap.org/mailman/listinfo/winpcap-users


More information about the Winpcap-users mailing list