public unsafe PacketCommunicatorReceiveResult ReceiveSomePackets(out int countGot, int maxPackets, HandlePacket callback) { this.AssertMode(PacketCommunicatorMode.Capture); PcapDataLink dataLink = new PcapDataLink(\u003CModule\u003E.pcap_datalink(this._pcapDescriptor)); PacketCommunicator.PacketHandler packetHandler = new PacketCommunicator.PacketHandler(callback, dataLink); PacketCommunicator.HandlerDelegate handlerDelegate = new PacketCommunicator.HandlerDelegate(packetHandler.Handle); // ISSUE: cast to a function pointer type __FnPtr <void (byte *, pcap_pkthdr *, byte *)> local = (__FnPtr <void (byte *, pcap_pkthdr *, byte *)>)(IntPtr) Marshal.GetFunctionPointerForDelegate((Delegate)handlerDelegate).ToPointer(); countGot = \u003CModule\u003E.pcap_dispatch(this._pcapDescriptor, maxPackets, local, (byte *)0); GC.KeepAlive((object)handlerDelegate); switch (countGot) { case -2: countGot = 0; return(PacketCommunicatorReceiveResult.BreakLoop); case -1: throw PcapError.BuildInvalidOperation("Failed reading from device", this._pcapDescriptor); case 0: if (packetHandler.PacketCounter != 0) { countGot = packetHandler.PacketCounter; return(PacketCommunicatorReceiveResult.Eof); } break; } return(PacketCommunicatorReceiveResult.Ok); }
public unsafe PacketCommunicatorReceiveResult ReceiveStatistics(int count, HandleStatistics callback) { this.AssertMode(PacketCommunicatorMode.Statistics); PacketCommunicator.HandlerDelegate handlerDelegate = new PacketCommunicator.HandlerDelegate(new PacketCommunicator.StatisticsHandler(callback).Handle); // ISSUE: cast to a function pointer type __FnPtr <void (byte *, pcap_pkthdr *, byte *)> local = (__FnPtr <void (byte *, pcap_pkthdr *, byte *)>)(IntPtr) Marshal.GetFunctionPointerForDelegate((Delegate)handlerDelegate).ToPointer(); int num = \u003CModule\u003E.pcap_loop(this._pcapDescriptor, count, local, (byte *)0); GC.KeepAlive((object)handlerDelegate); if (num == -1) { throw PcapError.BuildInvalidOperation("Failed reading from device", this._pcapDescriptor); } return(num != -2 ? PacketCommunicatorReceiveResult.Ok : PacketCommunicatorReceiveResult.BreakLoop); }
public unsafe PacketCommunicatorReceiveResult ReceivePackets(int count, HandlePacket callback) { this.AssertMode(PacketCommunicatorMode.Capture); PcapDataLink dataLink = new PcapDataLink(\u003CModule\u003E.pcap_datalink(this._pcapDescriptor)); PacketCommunicator.PacketHandler packetHandler = new PacketCommunicator.PacketHandler(callback, dataLink); PacketCommunicator.HandlerDelegate handlerDelegate = new PacketCommunicator.HandlerDelegate(packetHandler.Handle); // ISSUE: cast to a function pointer type __FnPtr <void (byte *, pcap_pkthdr *, byte *)> local = (__FnPtr <void (byte *, pcap_pkthdr *, byte *)>)(IntPtr) Marshal.GetFunctionPointerForDelegate((Delegate)handlerDelegate).ToPointer(); int num = \u003CModule\u003E.pcap_loop(this._pcapDescriptor, count, local, (byte *)0); GC.KeepAlive((object)handlerDelegate); if (num == -2) { return(PacketCommunicatorReceiveResult.BreakLoop); } if (num == -1) { throw PcapError.BuildInvalidOperation("Failed reading from device", this._pcapDescriptor); } return(num == 0 && packetHandler.PacketCounter != count ? PacketCommunicatorReceiveResult.Eof : PacketCommunicatorReceiveResult.Ok); }