0

I have a program written in C++ and I have to convert it to C#.
This program reads some pcap files.
I have add a reference to the PcapDotNet library in my new C# project but the types are not the same as in C++, like:

pcap_t *fp;
char[] errbuf = new char[PCAP_ERRBUF_SIZE];
pcap_pkthdr header;

So I don't know what is the best way to proceed, find the corresponding types with C#, or import the DLL. I found in fact that many do it in the following way:

//pcap_t *fp;
[DllImport("wpcap.dll")]
static extern int fp;

but for now it doesn't work and it gives me error.
It doesn't see DllImport and says that a ; is missing, then also on the line below it says Invalid expression term 'static' and ';' expected.

The thing is, I don't have any devices or anything, the original C++ program just reads these pcap files extract the data ad does something else with it.

bryan kennedy
  • 6,969
  • 5
  • 43
  • 64
ayasha
  • 1,221
  • 5
  • 27
  • 46
  • @ayasha, what is the error? – user3165438 Sep 02 '14 at 08:27
  • It will be easier to find the C# types, otherwise you will need to marshal things. BTW Is your static inside a class? If not you will get errors. – doctorlove Sep 02 '14 at 09:03
  • the problem is that i dont know if some functions exist or not..like the header pcap_pkthdr, i dont think it exists in c#, same for the function pcap_next_ex or pcap_open_offline.. – ayasha Sep 02 '14 at 11:19

1 Answers1

0

If you want to use Pcap.Net to read pcap files, you can just follow the instructions in the Pcap.Net User Guide.

Specifically, see "Reading packets from a dump file" here.

brickner
  • 6,595
  • 3
  • 41
  • 54