[Winpcap-users] Problem with threading

Gianluca Varenni gianluca.varenni at cacetech.com
Sat Apr 21 18:20:10 GMT 2007


I don't think it would make any difference, in any case the thread function you are using has the wrong prototype (hence the need for the explicit cast in CreateThread).

The right prototype for the thread fcn passed to CreateThread is

DWORD WINAPI GetINetDevice(LPVOID lpParam);

Also, have you changed the C-runtime library from single threaded (the default one for VC6, I don't remember for more recent versions of VS/VC) to multithreaded?

Have a nice day
GV

  ----- Original Message ----- 
  From: Avelino Martins 
  To: winpcap-users at winpcap.org 
  Sent: Thursday, April 19, 2007 2:18 PM
  Subject: [Winpcap-users] Problem with threading


  Hello all, 
  despite all the threads i readed about issues on threading problems, i couldn't get to a conclusion at the specific issue of the function 
  pcap_findalldevs() hanging when called from a child thread, take the simple example:
   
  #include <pcap.h>
  #pragma comment(lib, "Wpcap.lib")
   
  void GetINetDevice()
  {
       pcap_if_t* alldevs;
       char errbuf[PCAP_ERRBUF_SIZE+1];
   
       /* Retrieve the device list */
       if(pcap_findalldevs(&alldevs, errbuf) == -1)
       {
            printf("Error in pcap_findalldevs: %s\n", errbuf);
            exit(1);
       }
       // Could not create thread
       MessageBox(NULL, "Sucess","",MB_OK);
   
       // Free the device list 
       pcap_freealldevs(alldevs);
  }
   
   
  int main()
  { 
       DWORD m_dwThreadID;
       HANDLE m_hThread;
       m_hThread = CreateThread(0,
                                               0,
                                               (LPTHREAD_START_ROUTINE)GetINetDevice,
                                               NULL,
                                               0,
                                               &m_dwThreadID);
       if(!m_hThread)
       {
            // Could not create thread
            MessageBox(NULL, "Thread error","",MB_OK);
       }
       return 0;
  }
   
  Is anyone able to tell me if the fact of the app hangs/exits on pcap_findalldevs(), is a known issue at winpcap, and if there is any workaround?
   
  Best Regards


------------------------------------------------------------------------------
  Uma nova forma de utilizar mensagens: Windows Live Messenger beta 


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


  _______________________________________________
  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/20070421/29409d46/attachment.htm


More information about the Winpcap-users mailing list