/// <summary> /// Writes a packet to the pcap dump file associated with this device. /// </summary> /// <param name="p">P.</param> /// <param name="h">The height.</param> public void Write(ReadOnlySpan <byte> p, ref PcapHeader h) { ThrowIfNotOpen("Cannot dump packet, device is not opened"); if (!DumpOpened) { throw new DeviceNotReadyException("Cannot dump packet, dump file is not opened"); } //Marshal header IntPtr hdrPtr = h.MarshalToIntPtr(); unsafe { fixed(byte *p_packet = p) { LibPcapSafeNativeMethods.pcap_dump(m_pcapDumpHandle, hdrPtr, new IntPtr(p_packet)); } } Marshal.FreeHGlobal(hdrPtr); }
/// <summary> /// Writes a packet to the pcap dump file associated with this device. /// </summary> public void Write(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); }