Geek vs. Nerd

Wednesday, October 26, 2011

WinPCap, C#, and VS2010



All I wanted to do was a send a single crafted packet in my C# application. Was that too much to ask? Apparently, yes. If you ended up looking at this post, you're probably having a similar issue. If you're trying to write a C# program in VS2010 that needs to send a custom individual packet, here's what you can do:


Step 0: (AKA: My setup before starting) Windows 7 Ultimate & Visual Studio 2010 Professional. This isn't necessarily required, it's just what I'm running.


Step 1: Download PCap.Net. Chances are, if you're trying to do something along these lines, you're already familiar with libpcap (the Linux library that tcpdump & Wireshark are built on) or WinPCap (the Windows C/C++ library that projects like Wireshark use on Windows systems). PCap.Net is a wrapper for WinPCap written in C, C++, & C#. It is made specifically for importing WinPCap functionality into C# / .NET projects. You need to download the most recent "Developer's Pack" and extract it somewhere on your machine.


Step 2: In your Visual Studio Project, Right-click on "References" in your Solution Explorer and select "Add Reference..."



Select the "Browse" tab at the top and navigate to your extracted PcapDotNet Developer's Pack. Decide if you are creating an x64 (64-bit) or x86 (32-bit) project and select the appropriate directory.








Once inside, navigate to 3rdParty/PcapDotNet. In this directory you will see several .dlls:


  • PcapDotNet.Analysis.dll

  • PcapDotNet.Base.dll

  • PcapDotNet.Core.dll

  • PcapDotNet.Core.Extensions.dll

  • PcapDotNet.Packets.dll




Highlight all of these .dlls (ctrl+A) and select "OK." You should now see them all listed under "References." You're now ready to get started with Pcap.NET!







Visit the PCap.NET project website for code examples on packet crafting, packet capturing, enumerating NIC (network interface card) information, and other related topics.


Labels: , , , ,