Failed opening file Error

Nov 24, 2012 at 5:50 AM
Edited Nov 28, 2012 at 8:31 AM

Hi,

i added the option to change ip in my code and i did it in 2 differents ways:

1. change single ip (to another ip)

2. change ip range: change specific ip and configure start ip and to how many ip i want to change this specific ip for example change the ip 79.180.12.12 to 1.1.1.1 and the range is 1000 ip's so i write a function that i send to this function the start ip (1.1.1.1) and this function returns list of 1000 valid ip's start from 1.1.1.1

my problen is that after few hundred ip's the InvalidOperationExeption was unhandled by the user code and the error is Failed opening file C:\myFile.pcap.

this error didn't happen if  i change the ip range to 100 ip's, only if i am try to change to 1000 ip's its happen after few hundred  ip's.

Stack Trace:

at PcapDotNet.Core.OfflinePacketCommunicator.OpenFile(String filename)   at PcapDotNet.Core.OfflinePacketCommunicator..ctor(String fileName)   at PcapDotNet.Core.OfflinePacketDevice.Open(Int32 snapshotLength, PacketDeviceOpenAttributes attributes, Int32 readTimeout)   at packetPlayer.Pcap.playCapture(PacketDevice packetDevice) in d:\Drivers\PacketPlayer\PacketPlayer\classes\Pcap.cs:line 170   at PacketPlayer.MainWin.<>c__DisplayClass49.<btnPlay_Click>b__16(Object s3, DoWorkEventArgs e3) in d:\Drivers\PacketPlayer\PacketPlayer\mainWindows.cs:line 918   at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)   at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)

 

Edit:

this error cause too when i am sending the packet in regular way without changing the packet, my application has List Box that i am add all the pcap files inside, and after few hundred files this error cause again, maybe it is memory issue ?

Coordinator
Dec 1, 2012 at 7:13 PM

Hi gshhar,

 

It's hard to say without seeing some code.

Can you give a simple code snippet that causes this exception?

 

Boaz.

Dec 2, 2012 at 7:53 AM
Edited Dec 2, 2012 at 7:54 AM

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).

 

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++;
                }
            }
        }
    }
Dec 2, 2012 at 9:30 AM
Edited Dec 2, 2012 at 9:32 AM

i also try your code sample Sending packets using Send Buffer, i took pcap file and run it in loop and again after 509 iteration same error

Coordinator
Dec 3, 2012 at 9:44 PM

Hi gshhar,

 

I've reproduced this and it seem to me like a bug in WinPcap.

I've sent an email to winpcap-bugs@winpcap.org and I hope to get a response that would help me solve it.

 

When you create an OfflineCommunicator, Pcap.Net opens the file using _wfopen() (or fopen(), it doesn't matter), and then calls pcap_fopen_offline().

When you dispose your OfflineCommunicator, Pcap.Net calls pcap_close().

It seems that there are files that are left open and that's why you process crashes on opening too many files.

Calling fclose() only crashes the process faster.

 

I hope I'll find a solution for this soon,

 

Boaz.

Dec 16, 2012 at 1:06 PM

any new with the bug ?

Coordinator
Dec 28, 2012 at 3:06 PM

Unfortunately not.

See http://www.winpcap.org/pipermail/winpcap-bugs/2012-December/001547.html

Jan 17, 2013 at 10:16 AM
Edited Jan 17, 2013 at 10:40 AM

I am having the same problem, i could only open the files upto 509. I have used wireshark's file dumping method to write the packets. Then used the following way to process the packets.

                OfflinePacketDevice selectedDevice = new OfflinePacketDevice(filename);
                PacketCommunicator communicator =
                selectedDevice.Open(65536,PacketDeviceOpenAttributes.Promiscuous,1000);    
                {
                    communicator.ReceivePackets(0, DispatcherHandler);
                    communicator.Dispose();
                }

   When the file count reaches 509 it shows an error that Failed to open the file . Is there any solution for this ?

     Following is the exception i got ...

    Failed opening file e:\packets\h_00510_20130117110311.Stack Trace  :   at PcapDotNet.Core.OfflinePacketCommunicator.OpenFile(String filename)   at PcapDotNet.Core.OfflinePacketDevice.Open(Int32 snapshotLength, PacketDeviceOpenAttributes attributes, Int32 readTimeout)   at PacketReader.PacketReader.PacketRead(String filename)

 

Thanks...

Coordinator
Jan 18, 2013 at 4:34 PM

Hi Gladiator123,

 

As I've mentioned above, this is a WinPcap bug as far as I understand.

You can open different processes to open different files.

 

I hope this helps,

 

Boaz.

Jan 19, 2013 at 5:19 AM
Edited Jan 19, 2013 at 5:21 AM

Ok . how can i do that. I need to read the files in one apllication itself. Is there any other way to read the packets? i just opened the file in other processes , but faced the same exception. Will you please suggest the way clearly?

Jan 19, 2013 at 5:43 AM
Edited Jan 19, 2013 at 6:05 AM

 

Coordinator
Jan 19, 2013 at 6:45 AM

I think you'll have to create a process for each 500 files read batch.

This will definitely make the code more complex, but I don't know how to solve it without the help of WinPcap people.

Mar 16, 2013 at 7:41 PM
Edited Mar 16, 2013 at 7:42 PM
Hi,

new Winpcap version is available (4.1.3) but the crash is still occur.
maybe fix from your side is require ?

thanks
Apr 15, 2013 at 5:32 PM
Any updates to this significant issue?
Apr 15, 2013 at 6:58 PM
is it possible maybe to restart Winpcap service or something to avoid this crash ?
Coordinator
Apr 16, 2013 at 7:06 AM
Hi,

Since there's no update in WinPcap on this, I'm considering removing support for non ASCII pcap filenames in the next version of WinPcap.
In order to implement non ASCII pcap filenames support I've used the less common WinPcap API, which seem to not work well for closing files.

I might keep a separate method for opening non ASCII filenames that will still cause this issue.

Boaz.
Apr 16, 2013 at 10:08 AM
when you think this version will be ready ?
Coordinator
Apr 20, 2013 at 10:57 AM
Hi gshhar,

No ETA for that.
This is purely volunteering so I get to it whenever I can prioritize time for that.

Boaz.
Coordinator
Apr 27, 2013 at 10:07 AM
I have fixed this issue in the code.
If you don't want to wait for the next Pcap.Net release, you can download and build the code.
Apr 28, 2013 at 12:08 AM
Edited Apr 28, 2013 at 12:12 AM
Good job Brickner! My solution was to use SharPcap and PcapDotNet together but would much rather just use PcapDotNet alone.

Was the problem items that werent being disposed properly by PcapDotNet?
Apr 29, 2013 at 11:35 PM
from where i can download this code ?
Coordinator
May 3, 2013 at 7:17 AM
The problem is still the bug in WinPcap.
http://www.winpcap.org/pipermail/winpcap-bugs/2012-December/001547.html

I just avoid using the problematic functions when the filenames are ASCII or ISO-8859-1.
If the filenames are other, I still use the problematic functions without the ability to properly release the files resources.

You can download the code by going to Source Code of the Pcap.Net project here.
May 4, 2013 at 11:55 AM
Edited May 10, 2013 at 11:43 AM
thsnks