[Winpcap-users] pcap_next_ex() not receiving packets

Ryan Fowler ryan.fowler at thomsonreuters.com
Tue Jul 1 13:47:35 GMT 2008


Hi,

 

I am trying to receive packets using pcap_next_ex(), but for some reason
I keep getting a timeout.  I know that packets are coming into the
machine because I can see them via WinDump.  The odd part is that when I
run WinDump concurrently with my test application, I start to see
packets in the test app (as well as in WinDump).  But without WinDump, I
get no packets on the test app at all.

 

I am guessing that there is something I need to do to "start" the packet
driver capturing, although I thought that's what pcap_open_live does, so
I'm not quite sure on that.

 

My code so far is a fairly liberal sampling of the pktdump_ex example:

 

      /* Open the adapter */

      if ((m_pSessionHandle = pcap_open_live(m_pReceiveDevice->name,
// name of the device

                                    65536,      // 65536 means the whole
packet will be captured.

                                    0,    // non promiscuous mode
(nonzero means promiscuous)

                                    1000,       // read timeout

                                    errbuf      // error buffer)) ==
NULL)

                  {

                        // Error code

                  }

 

      std::cout << "Filter: " << m_strFilter << std::endl;

      if ( !m_strFilter.empty() )

      {

            bpf_u_int32 NetMask = 0;

            struct bpf_program fcode;

 

            //compile the filter

            if(pcap_compile(m_pSessionHandle, &fcode,
const_cast<char*>(m_strFilter.c_str()), 1, NetMask) < 0)

            {

                  // Error code

            }

 

            //set the filter

            if(pcap_setfilter(m_pSessionHandle, &fcode)<0)

            {

                  // Error code

            }

      }

 

      /* At this point, we don't need the device list any more. Free it
*/

      pcap_freealldevs(alldevs);

 

And later on:

 

      while((res = pcap_next_ex( m_pSessionHandle, &header, &pkt_data))
>= 0)

      {

            if(res == 0)

            {

                  /* Timeout elapsed */

                  OutputDebugString(L"No packets!\n");

                  continue;

            }

//...

      }

 

 

Ryan Fowler
Software Engineer

Thomson Reuters 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winpcap.org/pipermail/winpcap-users/attachments/20080701/227fc148/attachment.htm


More information about the Winpcap-users mailing list