/// <summary> /// Marshal this structure into the platform dependent version and return /// and IntPtr to that memory /// /// NOTE: IntPtr MUST BE FREED via Marshal.FreeHGlobal() /// </summary> /// <returns> /// A <see cref="IntPtr"/> /// </returns> public IntPtr MarshalToIntPtr() { IntPtr hdrPtr; if (!isWindows) { // setup the structure to marshal var pkthdr = new PcapUnmanagedStructures.pcap_pkthdr_unix(); pkthdr.caplen = this.CaptureLength; pkthdr.len = this.PacketLength; pkthdr.ts.tv_sec = (IntPtr)this.Seconds; pkthdr.ts.tv_usec = (IntPtr)this.MicroSeconds; hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PcapUnmanagedStructures.pcap_pkthdr_unix))); Marshal.StructureToPtr(pkthdr, hdrPtr, true); } else { var pkthdr = new PcapUnmanagedStructures.pcap_pkthdr_windows(); pkthdr.caplen = this.CaptureLength; pkthdr.len = this.PacketLength; pkthdr.ts.tv_sec = (int)this.Seconds; pkthdr.ts.tv_usec = (int)this.MicroSeconds; hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PcapUnmanagedStructures.pcap_pkthdr_windows))); Marshal.StructureToPtr(pkthdr, hdrPtr, true); } return hdrPtr; }