pcap-sharp

pcap-sharp is a wrapper around libpcap, exposing its functionality to managed languages, such as C#, VB.NET, and Boo.

RC1 is available (0.1.0.0): [tar.bz2] [zip]

There is no API documentation yet, but reflection will expose most of what you need to know. Here is a quick example:

using System;
using PcapSharp;

public class MainClass {
  public static void Main(string[] args) {
    using (PcapHandle ph = Pcap.OpenLive(args[0], short.MaxValue, true, 5000)) {
      // Poll-driven model
      for (int i = 0; i < 10; i++) {
        Packet p = ph.ReadNext();
        Console.WriteLine(p.RealLength);
      }

      int j = 0;
      // Callback-driven model
      ph.Loop(-1, delegate(Packet p) {
        Console.WriteLine(p.RealLength);
        if (++j == 10) {
          ph.BreakLoop();
        }
      });
    }
  }
}

When run like ./pcap-test.exe eth0, the length of the first 20 packets captured from eth0 will be displayed.

If you have any comments or bug reports, just leave a comment on any of the posts about pcap-sharp.