3

I am using PcapDotNet DLL's in my application, and I am encountering a problem:

My application takes a PCap file (Wireshark file) and sends the packets to the network card. If I send a file or files many times (usually ~500 times), my application crashes with the error Failed opening file C:\file.pcap. I tried to ask in the project forum, but the developer isn't there permanently, so maybe someone else could help me here.

The error cause is here in inputCommunicator, and when the error occurs, this object value is null. Please note that this happens only after a few hundred iterations (approximately 500).

code:

    using (PacketCommunicator inputCommunicator = selectedInputDevice.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
    {
        using (mOutputCommunicator = selectedOutputDevice.Open(100, PacketDeviceOpenAttributes.Promiscuous, 1000))
        {                
            while (inputCommunicator.ReceivePacket(out packet) == PacketCommunicatorReceiveResult.Ok && _isStop) //fill the buffer with the packets from the file
            {
                using (PacketSendBuffer mSendBuffer = new PacketSendBuffer((uint)packet.Length * 4))
                {                                                                                       
                    else if (packet != null)
                    {
                        lastTime = packet.Timestamp;
                        mSendBuffer.Enqueue(packet); //put the packet in the buffer
                    }

                    mOutputCommunicator.Transmit(mSendBuffer, _isBurst); //send the packet
                    _numberOfSendPackets++;
                }
            }
        }
    }
Esoteric Screen Name
  • 6,082
  • 4
  • 29
  • 38
user1710944
  • 1,419
  • 4
  • 16
  • 17
  • Are you accessing the file on disk every iteration? If so, is there a reason why you are not holding it in memory through the whole process? is it possible that something else attempts to access the file while your process is running? – CodeWarrior Nov 30 '12 at 20:40
  • can you show more code.. for example how are you reading the file packet contents..? also are you reading this OffLine..? – MethodMan Nov 30 '12 at 20:44
  • yes, i am accessing the file on disk every iteration and no one attempts to access the file while i am do it and i can holding all the packets in buffer but what should i in case i am want to play different 500 files ? – user1710944 Nov 30 '12 at 20:46
  • Can you please provide more code..? also have you looked at this Link https://pcapdotnet.codeplex.com/wikipage?title=Pcap.Net%20Tutorial%20-%20Handling%20offline%20dump%20files – MethodMan Nov 30 '12 at 20:50
  • i know this link and i am using the sample of Sending packets using Send Buffer – user1710944 Nov 30 '12 at 20:59

1 Answers1

2

This is a bug in WinPcap. For the details, see http://www.winpcap.org/pipermail/winpcap-bugs/2012-December/001547.html

brickner
  • 6,595
  • 3
  • 41
  • 54