Beispiel #1
0
        public RASDisplay()
        {
            m_connected = true;

            var lpras     = new RAS();
            var lprasConn = new RASCONN();

            lprasConn.dwSize   = Marshal.SizeOf(typeof(RASCONN));
            lprasConn.hrasconn = IntPtr.Zero;

            int lpcb           = 0;
            int lpcConnections = 0;
            int nRet           = 0;

            lpcb = Marshal.SizeOf(typeof(RASCONN));

            nRet = RAS.RasEnumConnections(ref lprasConn, ref lpcb, ref
                                          lpcConnections);

            if (nRet != 0)
            {
                m_connected = false;
                return;
            }

            if (lpcConnections > 0)
            {
                //for (int i = 0; i < lpcConnections; i++)

                //{
                var stats = new RasStats();

                m_ConnectedRasHandle = lprasConn.hrasconn;
                RAS.RasGetConnectionStatistics(lprasConn.hrasconn, stats);


                m_ConnectionName = lprasConn.szEntryName;

                int Hours   = 0;
                int Minutes = 0;
                int Seconds = 0;

                Hours   = ((stats.dwConnectionDuration / 1000) / 3600);
                Minutes = ((stats.dwConnectionDuration / 1000) / 60) - (Hours * 60);
                Seconds = ((stats.dwConnectionDuration / 1000)) - (Minutes * 60) - (Hours * 3600);


                m_duration = Hours + " hours " + Minutes + " minutes " + Seconds + " secs";
                m_TX       = stats.dwBytesXmited;
                m_RX       = stats.dwBytesRcved;
                //}
            }
            else
            {
                m_connected = false;
            }


            int lpNames       = 1;
            int entryNameSize = 0;
            int lpSize        = 0;

            RasEntryName[] names = null;
            entryNameSize   = Marshal.SizeOf(typeof(RasEntryName));
            lpSize          = lpNames * entryNameSize;
            names           = new RasEntryName[lpNames];
            names[0].dwSize = entryNameSize;
            uint retval = RAS.RasEnumEntries(null, null, names, ref lpSize, out lpNames);

            //if we have more than one connection, we need to do it again
            if (lpNames > 1)
            {
                names = new RasEntryName[lpNames];
                for (int i = 0; i < names.Length; i++)
                {
                    names[i].dwSize = entryNameSize;
                }

                retval = RAS.RasEnumEntries(null, null, names, ref lpSize, out lpNames);
            }
            m_ConnectionNames = new string[names.Length];


            if (lpNames > 0)
            {
                for (int i = 0; i < names.Length; i++)
                {
                    m_ConnectionNames[i] = names[i].szEntryName;
                }
            }
        }
Beispiel #2
0
 internal static extern uint RasGetConnectionStatistics(
     IntPtr hRasConn,                // handle to the connection
     [In, Out] RasStats lpStatistics // buffer to receive statistics
     );