Hi Peter.

Which version of WinPcap are you using?
Can you confirm me that you are using WinPcap 3.1beta3/4? In this case, your code should capture from the generic ndiswan adapter, and you have discovered a bug in it (in wanpacket.dll). I'll work on the fix in the next couple of weeks (maybe sooner), and let you know.


Have a nice day
GV


----- Original Message ----- From: "phengmaly peter" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, December 08, 2004 1:37 PM
Subject: [WinPcap-users] pcap_next_ex timeout after WaitForMultipleObjects



Hello,

I'm new to winpcap, and right now I ran into a problem
concerning capturing
from multiple devices. I tried to solve this without using
multiple threads.
I supposed that when the 'WaitForMultipleObjects' releases
my thread,
at least one packet is ready to be read by 'pcap_next_ex'.
However, my experience
shows, that it works for a while, but after a few dozen
packets 'pcap_next_ex'
returns with timeout (0). Is it a bug, or I may have
misunderstood something ?

Thanks,
Peter

----- 8>< ----- 8>< ----- 8>< ----- 8>< ----- 8>< ----- 8><
----- 8>< -----


#define WPCAP
#include <pcap-int.h>

int main()
{
   char errbuf[PCAP_ERRBUF_SIZE];

   char *dev = pcap_lookupdev(errbuf);
   if (!dev)
   {
       printf("pcap_lookupdev(): %s\n", errbuf);
       exit(1);
   }

   bpf_u_int32 net, mask;
   if (pcap_lookupnet(dev, &net, &mask, errbuf) != 0)
   {
       printf("pcap_lookupnet(): %s\n", errbuf);
       exit(1);
   }

   pcap_t* descr = pcap_open_live(dev,65535,1,1000,errbuf);
   if (descr == NULL)
   {
       printf("pcap_open_live(): %s\n", errbuf);
       exit(1);
   }

   pcap_pkthdr *header;
   const u_char *packetData;
   HANDLE handleArray[ 1 ];
   handleArray[ 0 ] = pcap_getevent( descr );

   do
   {
//        int sysCallRetVal = WaitForMultipleObjects( 1,
handleArray, false, 500 );
       int sysCallRetVal = WaitForSingleObject(
handleArray[ 0 ], 500 );

       if ( sysCallRetVal == WAIT_TIMEOUT )
           printf( "!!!!!! WAIT_TIMEOUT !!!!!!!!\n" );
       else
       if ( sysCallRetVal == WAIT_OBJECT_0 )
       {
           printf( "!!!!!! PACKET !!!!!!!!\n" );

           int res = pcap_next_ex( descr, &header,
&packetData );
           printf("pcap_next_ex %d\n", res );
           if ( res == 0 )
               exit( 1 );
       }
   } while ( 1 );

   return 0;
}






================================================================== This is the WinPcap users list. It is archived at http://www.mail-archive.com/winpcap-users@winpcap.polito.it/

To unsubscribe use
mailto: [EMAIL PROTECTED]
==================================================================






================================================================== This is the WinPcap users list. It is archived at http://www.mail-archive.com/winpcap-users@winpcap.polito.it/

To unsubscribe use mailto: [EMAIL PROTECTED]
==================================================================

Reply via email to