Problems setting up Pcap.net in my project

Jun 7, 2011 at 8:12 PM

Hello,

I just started using pcap.net today. It seems intuitive and straight forward but im getting exceptions when i try to capture packets on my LOCAL network .

 

my setup :

-wpf 4.0 on Windows 7

-have multiple NICs on my machine.

- have referenced all dlls.

when I get to:

 selectedDevice.Ope (65536,PacketDeviceOpenAttributes.Promiscuous,1000))                                         {
Console.WriteLine("Listening on " + selectedDevice.Description + "...");

I get IO.FileNotFound exception then when I start reading the packets  i get another exception every 4 packets  " Sockets.SocketException" and "System.Net.WebException". where did I got wrong ? im using the same code provided on this forum in my project and im getting exceptions . please help ?

 

Thank you 

      

 

 

 

 

Coordinator
Jun 9, 2011 at 2:12 PM

These exception don't seem to do anything with Pcap.Net.

Do you use Sockets or System.Net namespace?

Can you give the minimum full code that causes the exceptions?

Jun 9, 2011 at 2:32 PM

Thank you so much for your reply. Im using the same exact code posted on this Forum to open the network adapter and capture packets. i did not have to use either namecpases because the code did not use any.

 

using System;
using System.Collections.Generic;
using PcapDotNet.Core;
using PcapDotNet.Packets;

namespace OpeningAnAdapterAndCapturingThePackets
{
    class Program
    {
        static void Main(string[] args)
        {
            // Send anonymous statistics about the usage of Pcap.Net
            PcapDotNet.Analysis.PcapDotNetAnalysis.OptIn = true;

            // Retrieve the device list from the local machine
            IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;

            if (allDevices.Count == 0)
            {
                Console.WriteLine("No interfaces found! Make sure WinPcap is installed.");
                return;
            }

            // Print the list
            for (int i = 0; i != allDevices.Count; ++i)
            {
                LivePacketDevice device = allDevices[i];
                Console.Write((i + 1) + ". " + device.Name);
                if (device.Description != null)
                    Console.WriteLine(" (" + device.Description + ")");
                else
                    Console.WriteLine(" (No description available)");
            }

            int deviceIndex = 0;
            do
            {
                Console.WriteLine("Enter the interface number (1-" + allDevices.Count + "):");
                string deviceIndexString = Console.ReadLine();
                if (!int.TryParse(deviceIndexString, out deviceIndex) ||
                    deviceIndex < 1 || deviceIndex > allDevices.Count)
                {
                    deviceIndex = 0;
                }
            } while (deviceIndex == 0);

            // Take the selected adapter
            PacketDevice selectedDevice = allDevices[deviceIndex - 1];

            // Open the device
            using (PacketCommunicator communicator = 
                selectedDevice.Open(65536,                                  // portion of the packet to capture
                                                                            // 65536 guarantees that the whole packet will be captured on all the link layers
                                    PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
                                    1000))                                  // read timeout
            {
                Console.WriteLine("Listening on " + selectedDevice.Description + "...");

                // start the capture
                communicator.ReceivePackets(0, PacketHandler);
            }
        }

        // Callback function invoked by Pcap.Net for every incoming packet
        private static void PacketHandler(Packet packet)
        {
            Console.WriteLine(packet.Timestamp.ToString("yyyy-MM-dd hh:mm:ss.fff") + " length:" + packet.Length);
        }
    }
}


 

Jun 9, 2011 at 2:46 PM

so once i run the code, i get FileNotFoundException in the output console of V@2010  which happens after

using (PacketCommunicator communicator = 
                selectedDevice.Open(65536,                                  // portion of the packet to capture
                                                                            // 65536 guarantees that the whole packet will be captured on all the link layers
                                    PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
                                    1000))                                  // read timeout

then when for every 5-10 packets i receive, i get  4 exceptions in the output console of VS2010

 

System.Socket.SocketExceptions;

System.Net.WebException;

System.Net.WebException;

System.Net.WebException;

 

 

Coordinator
Jun 11, 2011 at 12:17 PM

Do you have internet access where you do this?

 

Try to change the line

PcapDotNet.Analysis.PcapDotNetAnalysis.OptIn = true;

to false.

Jun 13, 2011 at 2:26 PM

No i dont have interent. it is a local network. and yes , once I used false , i stopped getting the SocketExceptions and WebException but i alway get FileNotFoundException. would this effect anything ? and why is it happening ?

Coordinator
Jun 24, 2011 at 11:18 AM

When exactly do you get the FileNotFoundException? On what function?