private IntPtr GetAdslIntPrt() { Rasconn lprasConn = new Rasconn { #if !NET_CORE DwSize = Marshal.SizeOf(typeof(Rasconn)), #else DwSize = Marshal.SizeOf <Rasconn>(), #endif Hrasconn = IntPtr.Zero }; int lpcConnections = 0; #if !NET_CORE var lpcb = Marshal.SizeOf(typeof(Rasconn)); #else var lpcb = Marshal.SizeOf <Rasconn>(); #endif var nRet = RasEnumConnections(ref lprasConn, ref lpcb, ref lpcConnections); if (nRet != 0) { return(IntPtr.Zero); } return(lprasConn.Hrasconn); }
private IntPtr GetAdslIntPrt() { var lprasConn = new Rasconn { Hrasconn = IntPtr.Zero }; var lpcConnections = 0; #if !NETSTANDARD var lpcb = Marshal.SizeOf(typeof(Rasconn)); #else var lpcb = Marshal.SizeOf <Rasconn>(); #endif var nRet = RasEnumConnections(ref lprasConn, ref lpcb, ref lpcConnections); return(nRet != 0 ? IntPtr.Zero : lprasConn.Hrasconn); }
internal static extern int RasEnumConnections ( ref Rasconn lprasconn, // buffer to receive connections data ref int lpcb, // size in bytes of buffer ref int lpcConnections // number of connections written to buffer );
public Adsl() { _mConnected = true; Rasconn lprasConn = new Rasconn { DwSize = Marshal.SizeOf <Rasconn>(), Hrasconn = IntPtr.Zero }; int lpcConnections = 0; var lpcb = Marshal.SizeOf <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 <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; } } }