This project is read-only.


May 1, 2011 at 10:53 AM

Hello! Your guide is written only in C#. Could you please help me, how to obtain device list and send packet in C++/CLI ?

Thank you very much!

May 1, 2011 at 8:47 PM

Yes, indeed it's written in C#.

I assume that anyone who knows C++/CLI also knows C# since C# is much easier.

Converting C# code to C++/CLI shouldn't be too hard if you know C++/CLI well, I'll try to do it here (without checking anything):

using namespace System;
using namespace System::Collections::Generic;
using namespace PcapDotNet::Core;

namespace ObtainingTheDeviceList
    ref class Program
        static void Main(array<System::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.");

            // Print the list
            for (int i = 0; i != allDevices->Count; ++i)
                LivePacketDevice^ device = allDevices[i];
                Console::Write((i + 1) + ". " + device->Name);
                if (device->Description != nullptr)
                    Console::WriteLine(" (" + device->Description + ")");
                    Console::WriteLine(" (No description available)");

I'm not sure that everything here is correct, but I think it's a good place to start.

I hope this helps,