/// <summary> /// Writes a packet to the pcap dump file associated with this device. /// </summary> /// <param name="p">The packet to write</param> public void Dump(Kavprot.Packets.RawPacket p) { var data = p.Data; var timeval = p.Timeval; var header = new PcapHeader(timeval.Seconds, timeval.MicroSeconds, (uint)data.Length, (uint)data.Length); Dump(data, header); }
/// <summary> /// Convert an unmanaged packet into a managed Kavprot.Packets.RawPacket /// </summary> /// <param name="header"> /// A <see cref="IntPtr"/> /// </param> /// <param name="data"> /// A <see cref="IntPtr"/> /// </param> /// <returns> /// A <see cref="Kavprot.Packets.RawPacket"/> /// </returns> protected virtual Kavprot.Packets.RawPacket MarshalRawPacket(IntPtr /* pcap_pkthdr* */ header, IntPtr data) { Kavprot.Packets.RawPacket p; // marshal the header var pcapHeader = new PcapHeader(header); var pkt_data = new byte[pcapHeader.CaptureLength]; Marshal.Copy(data, pkt_data, 0, (int)pcapHeader.CaptureLength); p = new Kavprot.Packets.RawPacket(LinkType, new Kavprot.Packets.PosixTimeval(pcapHeader.Seconds, pcapHeader.MicroSeconds), pkt_data); return(p); }
/// <summary> /// Writes a packet to the pcap dump file associated with this device. /// </summary> public void Dump(byte[] p, PcapHeader h) { ThrowIfNotOpen("Cannot dump packet, device is not opened"); if (!DumpOpened) { throw new DeviceNotReadyException("Cannot dump packet, dump file is not opened"); } //Marshal packet IntPtr pktPtr; pktPtr = Marshal.AllocHGlobal(p.Length); Marshal.Copy(p, 0, pktPtr, p.Length); //Marshal header IntPtr hdrPtr = h.MarshalToIntPtr(); LibPcapSafeNativeMethods.pcap_dump(m_pcapDumpHandle, hdrPtr, pktPtr); Marshal.FreeHGlobal(pktPtr); Marshal.FreeHGlobal(hdrPtr); }