[Winpcap-users] Correct Initialization for winpcap

matt jaffa mjaffa at gmail.com
Tue Mar 28 22:32:02 GMT 2006


Yeah I saw Bryan's reply, but adding those services (npf, nm) to my
service's depnedons mutli-string value didn't produce any different results.

On 3/28/06, Guy Harris <guy at alum.mit.edu> wrote:
>
>
> 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.



I did have something similar to that way before, but I was noticing as I was
passing the pointer to the thread the name of the device was being
corrupted. I never did use the strdup call though, maybe that would solve
that problem and can get rid of the set size of 256.

Thanks,
Matt

_______________________________________________
> Winpcap-users mailing list
> Winpcap-users at winpcap.org
> https://www.winpcap.org/mailman/listinfo/winpcap-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winpcap.org/pipermail/winpcap-users/attachments/20060328/a2e980e3/attachment.htm


More information about the Winpcap-users mailing list