[Winpcap-users] Correct Initialization for winpcap

Guy Harris guy at alum.mit.edu
Tue Mar 28 21:26:19 GMT 2006


On Mar 28, 2006, at 1:00 PM, matt jaffa wrote:

> I was wondering if how I was first initially using winpcap is the  
> correct way of doing it.
> So I am looking up all the devices then creating a thread for each  
> device to listen for packets on.
> Does this code look right?

Not entirely - see below.

> if(pcap_findalldevs(&alldevs, errbuf) == -1)    // This is where it  
> hangs when are program is a service

Did you see Bryan Kadzban's reply?

> char *deviceName = new char[256];
> sprintf(deviceName, "%s", d->name);
This assumes that the device name fits in 256 characters.  That's  
probably true, so it's probably not causing problems in your code,  
but, as a general programming practice, it's unsafe.

Also, the "sprintf" is overkill, as all you're doing is copying the  
string.

	char *Devicename = strdup(d->name);

would suffice.



More information about the Winpcap-users mailing list