private void LoopCallback(IntPtr param, IntPtr header, IntPtr pkt_data) { Marshal.PtrToStringAnsi(param); dotnetWinpCap.pcap_pkthdr _pkthdr1 = (dotnetWinpCap.pcap_pkthdr)Marshal.PtrToStructure(header, typeof(dotnetWinpCap.pcap_pkthdr)); byte[] buffer1 = new byte[_pkthdr1.caplen]; Marshal.Copy(pkt_data, buffer1, 0, (int)_pkthdr1.caplen); Marshal.PtrToStringAnsi(pkt_data); }
private dotnetWinpCap.PCAP_NEXT_EX_STATE ReadNextInternal(out PacketHeader p, out byte[] packet_data, out IntPtr pkthdr, out IntPtr pktdata) { pkthdr = IntPtr.Zero; pktdata = IntPtr.Zero; p = null; packet_data = null; if (this.pcap_t.ToInt32() == 0) { this.errbuf = new StringBuilder("No adapter is currently open"); return(dotnetWinpCap.PCAP_NEXT_EX_STATE.ERROR); } switch (dotnetWinpCap.pcap_next_ex(this.pcap_t, ref pkthdr, ref pktdata)) { case 0: return(dotnetWinpCap.PCAP_NEXT_EX_STATE.TIMEOUT); case 1: { dotnetWinpCap.pcap_pkthdr _pkthdr1 = (dotnetWinpCap.pcap_pkthdr)Marshal.PtrToStructure(pkthdr, typeof(dotnetWinpCap.pcap_pkthdr)); p = new PacketHeader(); p.Caplength = (int)_pkthdr1.caplen; p.Length = (int)_pkthdr1.len; p.ts = _pkthdr1.ts; packet_data = new byte[p.Length]; Marshal.Copy(pktdata, packet_data, 0, p.Length); return(dotnetWinpCap.PCAP_NEXT_EX_STATE.SUCCESS); } case -1: return(dotnetWinpCap.PCAP_NEXT_EX_STATE.ERROR); case -2: return(dotnetWinpCap.PCAP_NEXT_EX_STATE.EOF); } return(dotnetWinpCap.PCAP_NEXT_EX_STATE.UNKNOWN); }