Packet Sniffer SDK DLL Edition

HNLBSession wrapper for C#

 Previous Next

File: HNLBSession.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 HNLBSession.
    /// </summary>
    public partial class HNLBSession : Component
    {
        #region DLL exports

        /// <summary>
        /// Returns the creation time of TCP session, which localhost is participating in.
        /// </summary>
        /// <param name="hLbSes"></param>
        /// <param name="HiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "LbSesGetCreateTime")]
#if WIN64
        private static extern long LbSesGetCreateTime(IntPtr hLbSes);
#else
        private static extern uint LbSesGetCreateTime(IntPtr hLbSes, ref int HiValue);
#endif

        /// <summary>
        /// Returns the closing time of TCP session, which localhost is participating in.
        /// </summary>
        /// <param name="hLbSes"></param>
        /// <param name="HiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "LbSesGetCloseTime")]
#if WIN64
        private static extern long LbSesGetCloseTime(IntPtr hLbSes);
#else
        private static extern uint LbSesGetCloseTime(IntPtr hLbSes, ref int HiValue);
#endif

        /// <summary>
        /// Returns PID of the process on the local system, which is participating in TCP session.
        /// </summary>
        /// <param name="hLbSes"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "LbSesGetProcessId")]
        private static extern int LbSesGetProcessId(IntPtr hLbSes);

        /// <summary>
        /// Returns the direction of TCP session creation as it is defined in the HNLBDirection enumeration.
        /// </summary>
        /// <param name="hLbSes"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "LbSesGetDirection")]
        private static extern int LbSesGetDirection(IntPtr hLbSes);

        /// <summary>
        /// Returns HNLBHosts object handle.
        /// </summary>
        /// <param name="hLbSes"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "LbSesGetHosts")]
        private static extern IntPtr LbSesGetHosts(IntPtr hLbSes);

        /// <summary>
        /// Returns the size of data, sent by localhost to the remote host in bytes.
        /// </summary>
        /// <param name="hLbSes"></param>
        /// <param name="HiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "LbSesGetLocalDataSize")]
#if WIN64
        private static extern ulong LbSesGetLocalDataSize(IntPtr hLbSes);
#else
        private static extern uint LbSesGetLocalDataSize(IntPtr hLbSes, ref uint HiValue);
#endif

        /// <summary>
        /// Returns the size of data, received by the localhost from remote host in bytes.
        /// </summary>
        /// <param name="hLbSes"></param>
        /// <param name="HiValue"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "LbSesGetRemoteDataSize")]
#if WIN64
        private static extern ulong LbSesGetRemoteDataSize(IntPtr hLbSes);
#else
        private static extern uint LbSesGetRemoteDataSize(IntPtr hLbSes, ref uint HiValue);
#endif 

        /// <summary>
        /// Returns user-defined value, associated with TCP session.
        /// </summary>
        /// <param name="hLbSes"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "LbSesGetUserData")]
        private static extern IntPtr LbSesGetUserData(IntPtr hLbSes);

        /// <summary>
        /// Sets user-defined value, associated with TCP session.
        /// </summary>
        /// <param name="hLbSes"></param>
        /// <param name="UserData"></param>
        /// <returns></returns>
        [DllImport("pssdk.dll", EntryPoint = "LbSesSetUserData")]
        private static extern IntPtr LbSesSetUserData(IntPtr hLbSes, IntPtr UserData);

        #endregion

        /// <summary>
        /// Handle of the HNLBSession object.
        /// </summary>
        private IntPtr hLbSes = IntPtr.Zero;

        /// <summary>
        /// Constructop of the HNLBSession component object.
        /// </summary>
        public HNLBSession()
        {
            InitializeComponent();
        }

        #region HNLBSession properties

        /// <summary>
        /// Checks if the HNLBSession object has been created correctly.
        /// </summary>
        [Browsable(false)]
        public bool IsValid
        {
            get
            {
                return (hLbSes != IntPtr.Zero);
            }
        }

        /// <summary>
        /// Sets/Returns HNLBSession object handle.
        /// </summary>
        [Browsable(false)]
        public IntPtr Handle
        {
            get
            {
                return hLbSes;
            }
            set
            {
                hLbSes = value;
            }
        }

        /// <summary>
        /// Returns PID of the process on the local system, which is participating in TCP session.
        /// </summary>
        [Browsable(false)]
        public int ProcessId
        {
            get
            {
                return LbSesGetProcessId(hLbSes);
            }
        }

        /// <summary>
        /// Returns the direction of TCP session creation as it is defined in the HNLBDirection enumeration.
        /// </summary>
        [Browsable(false)]
        public HNLBDirection Direction
        {
            get
            {
                return (HNLBDirection)LbSesGetDirection(hLbSes);
            }
        }

        /// <summary>
        /// Returns HNLBHosts object handle.
        /// </summary>
        [Browsable(false)]
        public IntPtr Hosts
        {
            get
            {
                return LbSesGetHosts(hLbSes);
            }
        }

        /// <summary>
        /// Sets/Returns user-defined value, associated with TCP session.
        /// </summary>
        [Browsable(false)]
        public IntPtr UserData
        {
            get
            {
                return LbSesGetUserData(hLbSes);
            }
            set
            {
                LbSesSetUserData(hLbSes, value);
            }
        }

        /// <summary>
        /// Returns the creation time of TCP session, which localhost is participating in
        /// </summary>
        [Browsable(false)]
        public long CreateTime
        {
            get
            {
#if WIN64
                return LbSesGetCreateTime(hLbSes);
#else
                uint LowValue; int HighValue = 0;
                LowValue = LbSesGetCreateTime(hLbSes, ref HighValue);
                return ((((long)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the closing time of TCP session, which localhost is participating in.
        /// </summary>
        [Browsable(false)]
        public long CloseTime
        {
            get
            {
#if WIN64
                return LbSesGetCloseTime(hLbSes);
#else
                uint LowValue; int HighValue = 0;
                LowValue = LbSesGetCloseTime(hLbSes, ref HighValue);
                return ((((long)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the size of data, sent by localhost to the remote host in bytes.
        /// </summary>
        [Browsable(false)]
        public ulong LocalDataSize
        {
            get
            {
#if WIN64
                return LbSesGetLocalDataSize(hLbSes);
#else
                uint LowValue, HighValue = 0;
                LowValue = LbSesGetLocalDataSize(hLbSes, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

        /// <summary>
        /// Returns the size of data, received by the localhost from remote host in bytes.
        /// </summary>
        [Browsable(false)]
        public ulong RemoteDataSize
        {
            get
            {
#if WIN64
                return LbSesGetRemoteDataSize(hLbSes);
#else
                uint LowValue, HighValue = 0;
                LowValue = LbSesGetRemoteDataSize(hLbSes, ref HighValue);
                return ((((ulong)HighValue) << 32) + LowValue);
#endif
            }
        }

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