[Winpcap-users] Packet Capture fails on winpcap 4.1.2 for 16MB buffer

Pushkar Tiwari pushkartiwari at gmail.com
Mon Dec 19 12:51:00 PST 2011


Hi,
    I have written a piece of code to capture packets at very high
speed. I have writen my code using Packet API.
    I have set 12MB buffer using "PacketSetBuff" API. This code works
fine winpcap 4.1.1, but it fails on 4.1.2.

In 4.1.2 I get error while reading the packets, the
PacketReceivePacket API error out. Same piece of code works perfectly
fine with 4.1.1.

Then I played with my buffer setting and got it working on 4MB buffer
size on winpcap 4.1.1.

Are there some changes done on how the buffer is handled from 4.1.1 to
4.1.2? How can I make my code working on 4.1.2 wit same buffer size?

Environment details:

    Winpacp Version : 4.1.1
    OS : Win2k3
    Memory : 8GB


Code Snippet:


  int DriverWPcaP::initialize()
  {
  if ((_adapter = PacketOpenAdapter(const_cast<PCHAR>(_ifname.c_str()))) == 0)
  {
  //Log "Failed to open adapter "
  return 0;
  }


  unsigned int bufferSize = 12582912 //4MB


  if ((_packet = PacketAllocatePacket()) == 0)
  {
  //Log "Failed to allocate packet"
  return 0;
  }
  _buffer = new uint8_t[bufferSize];
  PacketInitPacket(_packet, _buffer, bufferSize);


  if (PacketSetHwFilter(_adapter, NDIS_PACKET_TYPE_PROMISCUOUS) == FALSE)
  {
  //Log "Failed to initialize promiscuous mode"
  return 0;
  }

  unsigned long bufferDimension = bufferSize;
  if (PacketSetBuff( _adapter, bufferSize) == FALSE)
  {
  return 0;
  }


  if (PacketSetReadTimeout( _adapter, 1000) == FALSE)
  {
  return 0;
  }


  if (PacketSetMinToCopy( _adapter, 1) == 7000000)
  {
  return 0;
  }


  PacketSetSnapLen(_adapter, 1518);


  }


  bool DriverWPcaP::read()
  {
  if (PacketReceivePacket(_adapter, _packet, TRUE) == FALSE)
  {
  return 0;
  }


  _bytesLeft = _packet->ulBytesReceived;
  _currentFrame = reinterpret_cast<bpf_hdr*>(_buffer);


  return (_bytesLeft > 0);
  }


Thanks,
Pushkar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winpcap.org/pipermail/winpcap-users/attachments/20111219/def85223/attachment.html>


More information about the Winpcap-users mailing list