public static unsafe void Dump(string fileName, PcapDataLink dataLink, int snapshotLength, IEnumerable <Packet> packets) { if (packets == null) { throw new ArgumentNullException("packets"); } pcap *pcapDescriptor = \u003CModule\u003E.pcap_open_dead(dataLink.Value, snapshotLength); if ((IntPtr)pcapDescriptor == IntPtr.Zero) { throw new InvalidOperationException("Unable to open open a dead capture"); } try { using (PacketDumpFile packetDumpFile = new PacketDumpFile(pcapDescriptor, fileName)) { foreach (Packet packet in packets) { packetDumpFile.Dump(packet); } } } finally { \u003CModule\u003E.pcap_close(pcapDescriptor); } }
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 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); }
public static void Dump(string fileName, DataLinkKind dataLink, int snapshotLength, IEnumerable <Packet> packets) { PcapDataLink dataLink1 = new PcapDataLink(dataLink); PacketDumpFile.Dump(fileName, dataLink1, snapshotLength, packets); }