public void ReadCapFile(string FilePath) { StringBuilder errbuf = new StringBuilder(PCAP_ERRBUF_SIZE); PcapHandle = pcap_open_offline(FilePath, errbuf); // handle error if (PcapHandle == IntPtr.Zero) { throw new Exception("Unable to open offline adapter: " + errbuf.ToString()); } pcap_handler Callback = new pcap_handler(PacketHandler); int ret = pcap_dispatch(PcapHandle, -1 /* -1 = infinite */, Callback, IntPtr.Zero); }
internal extern static int pcap_dispatch(IntPtr /* pcap_t* */ adaptHandle, int count, pcap_handler callback, IntPtr ptr);
internal static extern int pcap_dispatch(IntPtr /* pcap_t* */ adaptHandle, int count, pcap_handler callback, IntPtr ptr);
/// <summary> /// Read packets until cnt packets are processed or an error occurs. /// </summary> internal static int pcap_dispatch(IntPtr /* pcap_t* */ adaptHandle, int count, pcap_handler callback, IntPtr ptr) { return(UseWindows ? Windows.pcap_dispatch(adaptHandle, count, callback, ptr) : Unix.pcap_dispatch(adaptHandle, count, callback, ptr)); }
internal static extern int pcap_loop( [In] IntPtr p, [In] int cnt, [In][MarshalAs(UnmanagedType.FunctionPtr)] pcap_handler callback, [In] IntPtr user);