只需要5个
一般步骤是
[DllImport("wpcap.dll")]
private static extern int pcap_findalldevs(ref IntPtr devicelist, StringBuilder errbuf);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
private struct pcap_if
{
public IntPtr next;
public string name;
public string description;
public IntPtr addresses;
public uint flags;
}
pcap_findalldevs找到所有的网络接口
自己找到正确的那个
然后
[DllImport("wpcap.dll")]
private static extern void pcap_freealldevs(IntPtr devicelist);
调用这种非托管的dll,包括winapi,弄完一样几乎都要相应的free一下,也几乎都有一个相应的free方法,这是c#不太习惯的