[Winpcap-users] Re: pcap_freealldevs() causing program crash.

MqX mqx at low-axs.net
Wed Nov 16 14:21:36 GMT 2005


call pcap_freealldevs() after selecting/print a device-list:
" for(iCount = 0, d = devs; d != NULL; d = d->next, iCount++) "

if you call pcap_open, you have to need to call after or pcap_open will 
fail.

if you call pcap_freealldevs(devs), where 'devs' isnt initialized... it 
will always crash.
for some reason this can occur in multithread programs..
eg. if you call pcap_freealldevs() after the thread (which call 
pcap_findalldevs()) returned.

hope it helps..

mqx

> Does anyone know why, whenever I put in "pcap_freealldevs(devs);" into my
> cleanup code (that frees all the memory, etc...that my program uses), it
> always crashes?
>
> devs declaration:
> pcap_if_t *devs, *d; // Device list
>
> My cleanup code:
> void CDevice::Cleanup(){
>
> // Free the device list
> pcap_freealldevs(devs);
> }
>
> and how I'm using devs:
> void CDevice::Devices(){
> if(pcap_findalldevs(&devs, error) == -1){
> AfxMessageBox(error);
> } else{
> for(iCount = 0, d = devs; d != NULL; d = d->next, iCount++){
> if(d->description){
> cDescription[iCount] = d->description;
> }
>
> cDevice[iCount] = d->name;
> }
> }
> }
>
> I've been racking my brain for over an hour trying to figure out what I'm
> doing.
>
> (Note: I call Cleanup() in the WM_DESTROY Windows message)
>
>




More information about the Winpcap-users mailing list