Packet Sniffer SDK DLL Edition

HNFileAdapter wrapper for C#

 Previous Next

File: HNFileAdapter.cs

using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Runtime.InteropServices;

namespace microOLAP.PSSDK
{
    /// <summary>
    /// Summary description for HNFileAdapter.
    /// </summary>
    public partial class HNFileAdapter : Component
    {
        #region DLL Exports

        /// <summary>
        /// Creates an HNFileAdapter object. 
        /// </summary>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpCreate")]
        private static extern IntPtr FAdpCreate();

        /// <summary>
        /// Destroys an HNFileAdapter object.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpDestroy")]
        private static extern uint FAdpDestroy(IntPtr hFAdp);

        /// <summary>
        /// Shows HNFileAdapter working status. 
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpIsOpened")]
        private static extern bool FAdpIsOpened(IntPtr hFAdp);

        /// <summary>
        /// Returns the handle of the HNUserFilter object. 
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpGetUserFilter")]
        private static extern IntPtr FAdpGetUserFilter(IntPtr hFAdp);

        /// <summary>
        /// Sets the handle of the HNUserFilter object.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="hUserFilter"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpSetUserFilter")]
        private static extern IntPtr FAdpSetUserFilter(IntPtr hFAdp, IntPtr hUserFilter);

        /// <summary>
        /// Returns the status flag of the user-settable packet filter using. 
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpGetUserFilterActive")]
        private static extern bool FAdpGetUserFilterActive(IntPtr hFAdp);

        /// <summary>
        /// Sets the status flag of the user-settable packet filter using. 
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="bActiveBpf"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpSetUserFilterActive")]
        private static extern bool FAdpSetUserFilterActive(IntPtr hFAdp, bool bActiveBpf);

        /// <summary>
        /// Returns the status flag of the FastBPF using.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpGetUseFastUserFilter")]
        private static extern bool FAdpGetUseFastUserFilter(IntPtr hFAdp);

        /// <summary>
        /// Sets the status flag of the FastBPF using.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="bUseFastBpf"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpSetUseFastUserFilter")]
        private static extern bool FAdpSetUseFastUserFilter(IntPtr hFAdp, bool bUseFastBpf);

        /// <summary>
        /// Get max packet size (some CAP formats use this parameter).
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpGetMaxPacketSize")]
        private static extern uint FAdpGetMaxPacketSize(IntPtr hFAdp);

        /// <summary>
        /// Set max packet size (required for some CAP formats)
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="MaxPacketSize"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpSetMaxPacketSize")]
        private static extern uint FAdpSetMaxPacketSize(IntPtr hFAdp, uint MaxPacketSize);

        /// <summary>
        /// Get adapter auto mode status (ON/OFF)
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpGetAutoMode")]
        private static extern bool FAdpGetAutoMode(IntPtr hFAdp);

        /// <summary>
        /// Set adapter auto mode status (ON/OFF)
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="bIsAutoMode"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpSetAutoMode")]
        private static extern bool FAdpSetAutoMode(IntPtr hFAdp, bool bIsAutoMode);

        /// <summary>
        /// Get file size limit.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpGetSizeLimit")]
        private static extern uint FAdpGetSizeLimit(IntPtr hFAdp);

        /// <summary>
        /// Set file size limit.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="SizeLimit"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpSetSizeLimit")]
        private static extern uint FAdpSetSizeLimit(IntPtr hFAdp, uint SizeLimit);

        /// <summary>
        /// Get PSSDK adapter type (packets format).
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpGetMediumType")]
        private static extern PSSDKRES FAdpGetMediumType(IntPtr hFAdp);

        /// <summary>
        /// Set PSSDK adapter type (packets format).
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="MediumType"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpSetMediumType")]
        private static extern PSSDKRES FAdpSetMediumType(IntPtr hFAdp, int MediumType);

        /// <summary>
        /// Get CAP format.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpGetCapFormat")]
        private static extern PSSDKRES FAdpGetCapFormat(IntPtr hFAdp);

        /// <summary>
        /// Set CAP format.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="CapFormat"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpSetCapFormat")]
        private static extern PSSDKRES FAdpSetCapFormat(IntPtr hFAdp, int CapFormat);

        /// <summary>
        /// Returns the handle of the HNQueue object.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpGetQueue")]
        private static extern IntPtr FAdpGetQueue(IntPtr hFAdp);

        /// <summary>
        /// Sets the handle of the HNQueue object.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="hQue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpSetQueue")]
        private static extern IntPtr FAdpSetQueue(IntPtr hFAdp, IntPtr hQue);

        /// <summary>
        /// Returns the current file size.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="pHiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpGetFileSize")]
#if WIN64
        private static extern ulong FAdpGetFileSize(IntPtr hFAdp);
#else
        private static extern uint FAdpGetFileSize(IntPtr hFAdp, ref uint pHiValue);
#endif
        /// <summary>
        /// Get quantity of packets received by user's filter.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="pHiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpGetRecvCount")]
#if WIN64
        private static extern ulong FAdpGetRecvCount(IntPtr hFAdp);
#else
        private static extern uint FAdpGetRecvCount(IntPtr hFAdp, ref uint pHiValue);
#endif

        /// <summary>
        /// Returns the number of the packets passed by the user-settable packet filter.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="pHiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpGetAcceptCount")]
#if WIN64
        private static extern ulong FAdpGetAcceptCount(IntPtr hFAdp);
#else
        private static extern uint FAdpGetAcceptCount(IntPtr hFAdp, ref uint pHiValue);
#endif

        /// <summary>
        /// Returns the number of packets rejected by the user-settable packet filter.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="pHiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpGetRejectCount")]
#if WIN64
        private static extern ulong FAdpGetRejectCount(IntPtr hFAdp);
#else
        private static extern uint FAdpGetRejectCount(IntPtr hFAdp, ref uint pHiValue);
#endif

        /// <summary>
        /// Returns the number of the packets transferred to the application.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="pHiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpGetProcessCount")]
#if WIN64
        private static extern ulong FAdpGetProcessCount(IntPtr hFAdp);
#else
        private static extern uint FAdpGetProcessCount(IntPtr hFAdp, ref uint pHiValue);
#endif

        /// <summary>
        /// Returns adapter open time.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="pHiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpGetOpenTime")]
#if WIN64
        private static extern long FAdpGetOpenTime(IntPtr hFAdp);
#else
        private static extern uint FAdpGetOpenTime(IntPtr hFAdp, ref int pHiValue);
#endif

        /// <summary>
        /// Open file for stored traffic reading.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="lpFName"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpOpenFileW", CharSet = CharSet.Unicode)]
        private static extern PSSDKRES FAdpOpenFile(IntPtr hFAdp, string lpFName);

        /// <summary>
        /// Create file to store captured traffic.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="lpFName"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpCreateFileW", CharSet = CharSet.Unicode)]
        private static extern PSSDKRES FAdpCreateFile(IntPtr hFAdp, string lpFName);

        /// <summary>
        /// Close file.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpCloseFile")]
        private static extern PSSDKRES FAdpCloseFile(IntPtr hFAdp);

        /// <summary>
        /// Saves the packet into file.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="pPacket"></param>
        /// <param name="PacketSize"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpSyncSend")]
        private static extern PSSDKRES FAdpSyncSend(IntPtr hFAdp, IntPtr pPacket, uint PacketSize);

        /// <summary>
        /// Saves the packet into file.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="hPkt"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpSyncSendEx")]
        private static extern PSSDKRES FAdpSyncSendEx(IntPtr hFAdp, IntPtr hPkt);

        /// <summary>
        /// Returns next packet.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="hPkt"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpGetNextPacket")]
        private static extern PSSDKRES FAdpGetNextPacket(IntPtr hFAdp, IntPtr hPkt);

        /// <summary>
        /// Reset packets reading position to the first packet.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpRewindFile")]
        private static extern PSSDKRES FAdpRewindFile(IntPtr hFAdp);

        /// <summary>
        /// Sets the OnPacketReceive event.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="pfOnPacketReceive"></param>
        /// <param name="Param"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpSetOnPacketRecv")]
        private static extern IntPtr FAdpSetOnPacketRecv(IntPtr hFAdp, CallBackOnPacketReceive pfOnPacketReceive, IntPtr Param);

        /// <summary>
        /// Sets the OnThreadBegin event.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="pfOnThreadBegin"></param>
        /// <param name="Param"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpSetOnThreadBegin")]
        private static extern IntPtr FAdpSetOnThreadBegin(IntPtr hFAdp, CallBackOnThreadBegin pfOnThreadBegin, IntPtr Param);

        /// <summary>
        /// Sets the OnThreadEnd event.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="pfOnThreadEnd"></param>
        /// <param name="Param"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpSetOnThreadEnd")]
        private static extern IntPtr FAdpSetOnThreadEnd(IntPtr hFAdp, CallBackOnThreadEnd pfOnThreadEnd, IntPtr Param);

        /// <summary>
        /// Sets the OnFileClose event.
        /// </summary>
        /// <param name="hFAdp"></param>
        /// <param name="pfOnFileClose"></param>
        /// <param name="Param"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "FAdpSetOnFileClose")]
        private static extern IntPtr FAdpSetOnFileClose(IntPtr hFAdp, CallBackOnFileClose pfOnFileClose, IntPtr Param);

        #endregion

        #region HNFileAdapter events

        /// <summary>
        /// CallBack OnThreadBegin.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="ThParam"></param>
        private delegate void CallBackOnThreadBegin(IntPtr Param, ref IntPtr ThParam);

        /// <summary>
        /// CallBack OnThreadEnd.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="ThParam"></param>
        private delegate void CallBackOnThreadEnd(IntPtr Param, IntPtr ThParam);

        /// <summary>
        /// CallBack OnPacketReceive.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="ThParam"></param>
        /// <param name="hPacket"></param>
        /// <param name="pPacketData"></param>
        /// <param name="IncPacketSize"></param>
        private delegate void CallBackOnPacketReceive(IntPtr Param, IntPtr ThParam, IntPtr hPacket, IntPtr pPacketData, uint IncPacketSize);

        /// <summary>
        /// CallBack OnFileClose.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="ThParam"></param>
        /// <param name="Result"></param>
        private delegate void CallBackOnFileClose(IntPtr Param, IntPtr ThParam, uint Result);

        /// <summary>
        /// CallBack variable OnThreadBegin.
        /// </summary>
        private CallBackOnThreadBegin pfOnThreadBegin;

        /// <summary>
        /// CallBack variable OnThreadEnd.
        /// </summary>
        private CallBackOnThreadEnd pfOnThreadEnd;

        /// <summary>
        /// CallBack variable OnPacketReceive.
        /// </summary>
        private CallBackOnPacketReceive pfOnPacketReceive;

        /// <summary>
        /// CallBack variable OnFileClose.
        /// </summary>
        private CallBackOnFileClose pfOnFileClose;

        /// <summary>
        /// OnThreadBegin event handler.
        /// </summary>
        public event OnThreadBeginEventHandler OnThreadBegin;

        /// <summary>
        /// OnThreadEnd event handler.
        /// </summary>
        public event OnThreadEndEventHandler OnThreadEnd;

        /// <summary>
        /// OnPacketReceive event handler.
        /// </summary>
        public event OnPacketReceiveEventHandler OnPacketReceive;

        /// <summary>
        /// OnFileClose event handler.
        /// </summary>
        public event OnFileCloseEventHandler OnFileClose;

        #endregion

        /// <summary>
        /// IntPtr of the HNFileAdapter object.
        /// </summary>
        private IntPtr hFAdp = IntPtr.Zero;

        /// <summary>
        /// User (bpf) filter.
        /// </summary>
        private HNUserFilter userFilter = null;

        /// <summary>
        /// Receive packet queue.
        /// </summary>
        private HNQueue packetsQueue = null;

        /// <summary>
        /// Constructor of the HNFileAdapter object.
        /// </summary>
        public HNFileAdapter()
        {
            InitializeComponent();

            hFAdp = FAdpCreate();
            if (hFAdp != IntPtr.Zero)
            {
                pfOnThreadBegin = new CallBackOnThreadBegin(this.DoOnThreadBegin);
                FAdpSetOnThreadBegin(hFAdp, pfOnThreadBegin, IntPtr.Zero);

                pfOnThreadEnd = new CallBackOnThreadEnd(this.DoOnThreadEnd);
                FAdpSetOnThreadEnd(hFAdp, pfOnThreadEnd, IntPtr.Zero);

                pfOnPacketReceive = new CallBackOnPacketReceive(this.DoOnPacketReceive);
                FAdpSetOnPacketRecv(hFAdp, pfOnPacketReceive, IntPtr.Zero);

                pfOnFileClose = new CallBackOnFileClose(this.DoOnFileClose);
                FAdpSetOnFileClose(hFAdp, pfOnFileClose, IntPtr.Zero);
            }
        }

        /// <summary>
        /// Destroys an HNFileAdapter object.
        /// </summary>
        ~HNFileAdapter()
        {
            if (hFAdp != IntPtr.Zero) FAdpDestroy(hFAdp);
        }

        #region HNFileAdapter properties

        /// <summary>
        /// Shows HNFileAdapter working status.
        /// </summary>
        [Browsable(false)]
        public bool IsOpened
        {
            get
            {
                return FAdpIsOpened(hFAdp);
            }
        }

        /// <summary>
        /// Sets/Returns the handle of the HNUserFilter object.
        /// </summary>
        [Browsable(false)]
        public HNUserFilter UserFilter
        {
            get
            {
                if (FAdpGetUserFilter(hFAdp) != IntPtr.Zero)
                {
                    return userFilter;
                }
                else
                {
                    userFilter = null;
                    return userFilter;
                }
            }
            set
            {
                if (value != null)
                {
                    userFilter = value;
                    FAdpSetUserFilter(hFAdp, userFilter.Handle);
                }
                else
                {
                    FAdpSetUserFilter(hFAdp, IntPtr.Zero);
                }
            }
        }

        /// <summary>
        /// Sets/Returns the status flag of the user-settable packet filter using.
        /// </summary>
        public bool UserFilterActive
        {
            get
            {
                return FAdpGetUserFilterActive(hFAdp);
            }
            set
            {
                FAdpSetUserFilterActive(hFAdp, value);
            }
        }

        /// <summary>
        /// Sets/Returns the status flag of the FastBPF using.
        /// </summary>
        public bool UseFastUserFilter
        {
            get
            {
                return FAdpGetUseFastUserFilter(hFAdp);
            }
            set
            {
                FAdpSetUseFastUserFilter(hFAdp, value);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public uint MaxPacketSize
        {
            get
            {
                return FAdpGetMaxPacketSize(hFAdp);
            }
            set
            {
                FAdpSetMaxPacketSize(hFAdp, value);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public bool AutoMode
        {
            get
            {
                return FAdpGetAutoMode(hFAdp);
            }
            set
            {
                FAdpSetAutoMode(hFAdp, value);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public uint SizeLimit
        {
            get
            {
                return FAdpGetSizeLimit(hFAdp);
            }
            set
            {
                FAdpSetSizeLimit(hFAdp, value);
            }
        }

        /// <summary>
        /// Sets/Returns the type of the network adapter.
        /// </summary>
        public HNNetAdapterType MediumType
        {
            get
            {
                return (HNNetAdapterType)FAdpGetMediumType(hFAdp);
            }
            set
            {
                FAdpSetMediumType(hFAdp, (int)value);
            }
        }

        /// <summary>
        /// Sets/Returns the CAP file formats.
        /// </summary>
        public HNCapFormat CapFormat
        {
            get
            {
                return (HNCapFormat)FAdpGetCapFormat(hFAdp);
            }
            set
            {
                FAdpSetCapFormat(hFAdp, (int)value);
            }
        }

        /// <summary>
        /// Sets/Returns the HNQueue object.
        /// </summary>
        public HNQueue PacketsQueue
        {
            get
            {
                if (FAdpGetQueue(hFAdp) != IntPtr.Zero)
                {
                    return packetsQueue;
                }
                else
                {
                    packetsQueue = null;
                    return packetsQueue;
                }
            }
            set
            {
                if (value != null)
                {
                    packetsQueue = value;
                    FAdpSetQueue(hFAdp, packetsQueue.Handle);
                }
                else
                {
                    FAdpSetQueue(hFAdp, IntPtr.Zero);
                }
            }
        }


        /// <summary>
        /// 
        /// </summary>
        [Browsable(false)]
        public ulong FileSize
        {
            get
            {
#if WIN64
                return FAdpGetFileSize(hFAdp);
#else
                uint LowValue = 0; uint HighValue = 0;
                LowValue = FAdpGetFileSize(hFAdp, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns quantity of packets received by user's filter.
        /// </summary>
        [Browsable(false)]
        public uint RecvCount32
        {
            get
            {
#if WIN64
                return (uint)FAdpGetRecvCount(hFAdp);
#else
                uint HighValue = 0;
                return FAdpGetRecvCount(hFAdp, ref HighValue);
#endif
            }
        }

        /// <summary>
        /// Returns quantity of packets received by user's filter.
        /// </summary>
        [Browsable(false)]
        public ulong RecvCount64
        {
            get
            {
#if WIN64
                return FAdpGetRecvCount(hFAdp);
#else
                uint LowValue = 0, HighValue = 0;
                LowValue = FAdpGetRecvCount(hFAdp, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets passed by the user-settable packet filter.
        /// </summary>
        [Browsable(false)]
        public uint AcceptCount32
        {
            get
            {
#if WIN64
                return (uint)FAdpGetAcceptCount(hFAdp);
#else
                uint HighValue = 0;
                return FAdpGetAcceptCount(hFAdp, ref HighValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets passed by the user-settable packet filter.
        /// </summary>
        [Browsable(false)]
        public ulong AcceptCount64
        {
            get
            {
#if WIN64
                return FAdpGetAcceptCount(hFAdp);
#else
                uint LowValue = 0, HighValue = 0;
                LowValue = FAdpGetAcceptCount(hFAdp, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of packets rejected by the user-settable packet filter.
        /// </summary>
        [Browsable(false)]
        public uint RejectCount32
        {
            get
            {
#if WIN64
                return (uint)FAdpGetRejectCount(hFAdp);
#else
                uint HighValue = 0;
                return FAdpGetRejectCount(hFAdp, ref HighValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of packets rejected by the user-settable packet filter.
        /// </summary>
        [Browsable(false)]
        public ulong RejectCount64
        {
            get
            {
#if WIN64
                return FAdpGetRejectCount(hFAdp);
#else
                uint LowValue = 0, HighValue = 0;
                LowValue = FAdpGetRejectCount(hFAdp, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets transferred to the application.
        /// </summary>
        [Browsable(false)]
        public uint ProcessCount32
        {
            get
            {
#if WIN64
                return (uint)FAdpGetProcessCount(hFAdp);
#else
                uint HighValue = 0;
                return FAdpGetProcessCount(hFAdp, ref HighValue);
#endif
            }
        }

        /// <summary>
        /// Returns the number of the packets transferred to the application.
        /// </summary>
        [Browsable(false)]
        public ulong ProcessCount64
        {
            get
            {
#if WIN64
                return FAdpGetProcessCount(hFAdp);
#else
                uint LowValue = 0, HighValue = 0;
                LowValue = FAdpGetProcessCount(hFAdp, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the time of the latest opening of the current network adapter.
        /// </summary>
        [Browsable(false)]
        public long OpenTime
        {
            get
            {
#if WIN64
                return FAdpGetOpenTime(hFAdp);
#else
                uint LowValue = 0; int HighValue = 0;
                LowValue = FAdpGetOpenTime(hFAdp, ref HighValue);
                return ((((long)HighValue) << 32) + LowValue);
#endif
            }
        }

        #endregion

        #region HNFileAdapter methods

        /// <summary>
        /// 
        /// </summary>
        /// <param name="lpFName"></param>
        /// <returns></returns>
        public PSSDKRES OpenFile(string lpFName)
        {
            return (PSSDKRES)FAdpOpenFile(hFAdp, lpFName);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="lpFName"></param>
        /// <returns></returns>
        public PSSDKRES CreateFile(string lpFName)
        {
            return (PSSDKRES)FAdpCreateFile(hFAdp, lpFName);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public PSSDKRES CloseFile()
        {
            return (PSSDKRES)FAdpCloseFile(hFAdp);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="pPacket"></param>
        /// <param name="PacketSize"></param>
        /// <returns></returns>
        public PSSDKRES SyncSend(IntPtr pPacket, uint PacketSize)
        {
            return (PSSDKRES)FAdpSyncSend(hFAdp, pPacket, PacketSize);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="hPkt"></param>
        /// <returns></returns>
        public PSSDKRES SyncSendEx(IntPtr hPkt)
        {
            return (PSSDKRES)FAdpSyncSendEx(hFAdp, hPkt);
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="hPkt"></param>
        /// <returns></returns>
        public PSSDKRES GetNextPacket(IntPtr hPkt)
        {
            return (PSSDKRES)FAdpGetNextPacket(hFAdp, hPkt);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public PSSDKRES RewindFile()
        {
            return (PSSDKRES)FAdpRewindFile(hFAdp);
        }

        #endregion

        #region HNFileAdapter callBacks

        /// <summary>
        /// Tracks the creating of the internal component thread.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="ThParam"></param>
        private void DoOnThreadBegin(IntPtr Param, ref IntPtr ThParam)
        {
            if (OnThreadBegin != null)
                OnThreadBegin(this, ref ThParam);
        }

        /// <summary>
        /// Tracks the closing of the internal component thread.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="ThParam"></param>
        private void DoOnThreadEnd(IntPtr Param, IntPtr ThParam)
        {
            if (OnThreadEnd != null)
                OnThreadEnd(this, ThParam);
        }

        /// <summary>
        /// Occurs immediately after a packet has been received by the file adapter.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="ThParam"></param>
        /// <param name="hPacket"></param>
        /// <param name="pPacketData"></param>
        /// <param name="IncPacketSize"></param>
        private void DoOnPacketReceive(IntPtr Param, IntPtr ThParam, IntPtr hPacket, IntPtr pPacketData, uint IncPacketSize)
        {
            if (OnPacketReceive != null)
                OnPacketReceive(this, ThParam, hPacket, pPacketData, IncPacketSize);
        }

        /// <summary>
        /// Occurs immediately after a CAP file closed.
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="ThParam"></param>
        /// <param name="Result"></param>
        private void DoOnFileClose(IntPtr Param, IntPtr ThParam, uint Result)
        {
            if (OnFileClose != null)
                OnFileClose(this, ThParam, Result);
        }

        #endregion
    }
}
See also:HNFileAdapter, All wrappers in one ZIP archive