[Winpcap-users] Correct Initialization for winpcap

Ramiro Polla ramiro86 at hotmail.com
Tue Mar 28 21:23:57 GMT 2006


Hello Matt,

Depending on what StartRoutine does, it might not be a good idea to spawn a thread for each interface. In my case, all interfaces use a single list, so each having a thread would make the program more complex because of so many tasks acessing the list (I'd need mutexes and locks and such).

My current implementation (working steadily and fast for a while now) is to create a single thread for all the interfaces, and loop through the devices.

Bye,
Ramiro Polla
  ----- Original Message ----- 
  From: matt jaffa 
  To: winpcap-users at winpcap.org 
  Sent: Tuesday, March 28, 2006 6:00 PM
  Subject: [Winpcap-users] Correct Initialization for winpcap


  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/20060328/d546d9ef/attachment.htm


More information about the Winpcap-users mailing list