[Winpcap-users] Re: Correct Initialization for winpcap

Gianluca Varenni gianluca.varenni at cacetech.com
Thu Mar 30 00:35:46 GMT 2006


  ----- Original Message ----- 
  From: matt jaffa 
  To: winpcap-users at winpcap.org 
  Sent: Wednesday, March 29, 2006 3:23 PM
  Subject: [Winpcap-users] Re: Correct Initialization for winpcap


  So what I am really asking is all about the pcap_findalldevs call. Is this a neccessary call or is 

Yes, if you want to know the list of available adapters.

  there another call I can use? Why was pcap_lookupdev() depracated? 

Because it is broken: first of all it's not thread safe at all (it returns an internal static buffer allocated by wpcap.dll), and it has a different behavior on windows vs. other platforms (if I remember well, on all the other platforms except windows it returns the first adapter, only). findalldevs returns more information like the IP addresses and the description of each adapter, if available.

  Is there anyway to get the default adapter, active device on the system? 

No. You need to use either pcap_findalldevs of pcap_lookupdev, which end up in calling PacketGetAdapterNames. I think there's some bug (or in any case strange behavior) in PacketGetAdapterNames that causes the problems you are encountering. Can you provide us some code that we can use to debug the issue? 

Have a nice day
GV
 
  Thanks,
  Matt
   
  On 3/28/06, matt jaffa <mjaffa at gmail.com> wrote: 
    Hi,

    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?  (Code is below).

    Thanks,
    Matt

    pcap_if_t *alldevs;

    pcap_if_t *d;


    int i=0; 

    char errbuf[PCAP_ERRBUF_SIZE]; 




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

    fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);


    return; 
    }


    for(d=alldevs; d; d=d->next) 
    { 


    char *deviceName = new char[256]; 
    sprintf(deviceName, "%s", d->name);

    CreateThread(NULL, 0, &StartRoutine, deviceName, 0, NULL);     // Each of these threads listen for packets on each device

    }

    pcap_freealldevs(alldevs);





------------------------------------------------------------------------------


  _______________________________________________
  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/20060329/faf760e7/attachment.htm


More information about the Winpcap-users mailing list