Ejemplo n.º 1
0
 internal static extern uint RasGetConnectionStatistics(
     IntPtr hRasConn,                   // handle to the connection
     [In, Out] RasStats lpStatistics    // buffer to receive statistics
     );
Ejemplo n.º 2
0
        public Adsl()
        {
            _mConnected = true;

            Rasconn lprasConn = new Rasconn
            {
                DwSize   = Marshal.SizeOf(typeof(Rasconn)),
                Hrasconn = IntPtr.Zero
            };


            int lpcConnections = 0;
            var lpcb           = Marshal.SizeOf(typeof(Rasconn));

            var nRet = RasEnumConnections(ref lprasConn, ref lpcb, ref
                                          lpcConnections);

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

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

                //{
                RasStats stats = new RasStats();

                _mConnectedRasHandle = lprasConn.Hrasconn;
                RasGetConnectionStatistics(lprasConn.Hrasconn, stats);


                _mConnectionName = lprasConn.SzEntryName;

                var hours   = stats.dwConnectionDuration / 1000 / 3600;
                var minutes = stats.dwConnectionDuration / 1000 / 60 - hours * 60;
                var seconds = stats.dwConnectionDuration / 1000 - minutes * 60 - hours * 3600;


                _mDuration = hours + " hours " + minutes + " minutes " + seconds + " secs";
                _mTx       = stats.dwBytesXmited;
                _mRx       = stats.dwBytesRcved;
                //}
            }
            else
            {
                _mConnected = false;
            }


            int lpNames = 1;

            var entryNameSize = Marshal.SizeOf(typeof(RasEntryName));
            var lpSize        = lpNames * entryNameSize;

            var names = new RasEntryName[lpNames];

            names[0].dwSize = entryNameSize;

            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;
                }

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


            if (lpNames > 0)
            {
                for (int i = 0; i < names.Length; i++)
                {
                    _mConnectionNames[i] = names[i].szEntryName;
                }
            }
        }