Esempio n. 1
0
        public static void CreateEntry(string entryName, string url, RASDEVINFO device)
        {
            var props = new RASENTRY
            {
                dwSize              = Marshal.SizeOf <RASENTRY>(),
                szAutodialDll       = "",
                szAutodialFunc      = "",
                szAreaCode          = "",
                szCustomDialDll     = "",
                szDeviceType        = device.szDeviceType,
                szDeviceName        = device.szDeviceName,
                dwType              = (int)(RasEntryTypes.Vpn),                         //vpn
                dwEncryptionType    = 1,                                                // require
                dwFramingProtocol   = (int)RasFramingProtocol.Ppp,
                dwfNetProtocols     = (int)(RasNetProtocols.Ip | RasNetProtocols.Ipv6), //IP and IPv6
                dwfOptions          = (int)(RasEntryOptions.RemoteDefaultGateway | RasEntryOptions.ModemLights | RasEntryOptions.RequireEncrptedPw | RasEntryOptions.PreviewUserPw | RasEntryOptions.PreviewDomain | RasEntryOptions.ShowDialingProgress),
                szLocalPhoneNumber  = url,
                szScript            = "",
                dwVpnStrategy       = 5, //SstpOnly
                szX25Address        = "",
                szX25Facilities     = "",
                szX25PadType        = "",
                szX25UserData       = "",
                dwfOptions2         = (int)(RasEntryOptions2.DoNotNegotiateMultilink | RasEntryOptions2.ReconnectIfDropped | RasEntryOptions2.UseTypicalSettings | RasEntryOptions2.IPv6RemoteDefaultGateway),
                szDnsSuffix         = "",
                szPrerequisitePbk   = "",
                szPrerequisiteEntry = "",
                dwRedialCount       = 3000,
                dwRedialPause       = 3,
            };

            Checked("RasSetEntryProperties", VpnNative.RasSetEntryProperties(null, entryName, ref props, Marshal.SizeOf <RASENTRY>(), IntPtr.Zero, 0));
        }
Esempio n. 2
0
        internal static bool IsHangUp(IntPtr hConn)
        {
            RASCONNSTATUS status = new RASCONNSTATUS();

            status.size = Marshal.SizeOf <RASCONNSTATUS>();

            return(VpnNative.RasGetConnectStatus(hConn, ref status) != 0); // as described in Hangup description
        }
Esempio n. 3
0
        public static RAS_STATS GetStatisitcs(IntPtr hConn)
        {
            RAS_STATS status = new RAS_STATS();

            status.dwSize = (uint)Marshal.SizeOf <RAS_STATS>();

            Checked("RasGetConnectionStatistics", VpnNative.RasGetConnectionStatistics(hConn, ref status));
            return(status);
        }
Esempio n. 4
0
        public static RASCONNSTATUS GetState(IntPtr hConn)
        {
            RASCONNSTATUS status = new RASCONNSTATUS();

            status.size = Marshal.SizeOf <RASCONNSTATUS>();

            Checked("RasGetConnectStatus", VpnNative.RasGetConnectStatus(hConn, ref status));
            return(status);
        }
Esempio n. 5
0
        public static RAS_PROJECTION_INFO GetProjectionInfoEx(IntPtr hConn)
        {
            RAS_PROJECTION_INFO info = new RAS_PROJECTION_INFO();

            info.version = 4;
            int dwSize = Marshal.SizeOf <RAS_PROJECTION_INFO>();

            Checked("GetProjectionInfoEx", VpnNative.RasGetProjectionInfoEx(hConn, ref info, ref dwSize));
            return(info);
        }
Esempio n. 6
0
        internal static string RasErrorMessage(uint errorCode)
        {
            StringBuilder sb = new StringBuilder(1024);

            if (VpnNative.RasGetErrorString(errorCode, sb, sb.Capacity) > 0)
            {
                return($"Error {errorCode}");
            }
            return($"{errorCode}: {sb}");
        }
Esempio n. 7
0
        public static RASENTRYNAME[] GetEntryNames()
        {
            int cb = 0;

            CheckedInit("RasEnumEntries", VpnNative.RasEnumEntries(IntPtr.Zero, IntPtr.Zero, null, ref cb, out var entries));
            if (entries > 0)
            {
                RASENTRYNAME[] buffer = new RASENTRYNAME[entries];
                buffer[0].dwSize = Marshal.SizeOf <RASENTRYNAME>();
                Checked("RasEnumEntries", VpnNative.RasEnumEntries(IntPtr.Zero, IntPtr.Zero, buffer, ref cb, out entries));
                return(buffer);
            }
            return(new RASENTRYNAME[0]);
        }
Esempio n. 8
0
        public static RASCONN[] GetConnections()
        {
            int cb = 0;

            CheckedInit("RasEnumConnections", VpnNative.RasEnumConnections(null, ref cb, out var connectionCount));
            if (connectionCount > 0)
            {
                RASCONN[] buffer = new RASCONN[connectionCount];
                buffer[0].dwSize = Marshal.SizeOf <RASCONN>();
                Checked("RasEnumConnections", VpnNative.RasEnumConnections(buffer, ref cb, out connectionCount));
                return(buffer);
            }
            return(new RASCONN[0]);
        }
Esempio n. 9
0
        public static RASDEVINFO[] GetDevices()
        {
            int cb = 0;

            CheckedInit("RasEnumDevices", VpnNative.RasEnumDevices(null, ref cb, out var devices));
            if (devices > 0)
            {
                RASDEVINFO[] buffer = new RASDEVINFO[devices];
                buffer[0].dwSize = Marshal.SizeOf <RASDEVINFO>();
                Checked("RasEnumDevices", VpnNative.RasEnumDevices(buffer, ref cb, out devices));
                return(buffer);
            }
            return(new RASDEVINFO[0]);
        }
Esempio n. 10
0
        public static WaitHandle RegisterForTermination(IntPtr handle)
        {
            var ev = new AutoResetEvent(false);

            try
            {
                Checked("RasEnumEntries", VpnNative.RasConnectionNotification(handle, ev.SafeWaitHandle, RASCN.Disconnection));
            }
            catch
            {
                ev.Dispose();
                throw;
            }
            return(ev);
        }
Esempio n. 11
0
 public static void DeleteEntry(string name) => Logged("RasDeleteEntry", VpnNative.RasDeleteEntry(null, name));
Esempio n. 12
0
 public static void HangUp(IntPtr hConn) => Logged("RasHangUp", VpnNative.RasHangUp(hConn));