/// <summary> /// Sets the network protocols on a <see cref="RasEntry"/> for the flags specified. /// </summary> /// <param name="entry">The entry whose options to set.</param> /// <param name="value">The flags of the entry.</param> public static void SetRasNetworkProtocols(RasEntry entry, NativeMethods.RASNP value) { if (entry != null) { RasNetworkProtocols protocols = entry.NetworkProtocols; #pragma warning disable 0618 protocols.NetBeui = Utilities.HasFlag(value, NativeMethods.RASNP.NetBeui); #pragma warning restore 0618 protocols.Ipx = Utilities.HasFlag(value, NativeMethods.RASNP.Ipx); protocols.IP = Utilities.HasFlag(value, NativeMethods.RASNP.IP); #if (WIN2K8 || WIN7 || WIN8) protocols.IPv6 = Utilities.HasFlag(value, NativeMethods.RASNP.IPv6); #endif } }
/// <summary> /// Retrieves the <see cref="NativeMethods.RASNP"/> flags for the network protocols specified. /// </summary> /// <param name="value">The network protocols whose flags to retrieve.</param> /// <returns>The <see cref="NativeMethods.RASNP"/> flags.</returns> public static NativeMethods.RASNP GetRasNetworkProtocols(RasNetworkProtocols value) { NativeMethods.RASNP protocols = NativeMethods.RASNP.None; if (value != null) { #pragma warning disable 0618 protocols |= (NativeMethods.RASNP)Utilities.SetFlag(value.NetBeui, NativeMethods.RASNP.NetBeui); #pragma warning restore 0618 protocols |= (NativeMethods.RASNP)Utilities.SetFlag(value.Ipx, NativeMethods.RASNP.Ipx); protocols |= (NativeMethods.RASNP)Utilities.SetFlag(value.IP, NativeMethods.RASNP.IP); #if (WIN2K8 || WIN7 || WIN8) protocols |= (NativeMethods.RASNP)Utilities.SetFlag(value.IPv6, NativeMethods.RASNP.IPv6); #endif } return(protocols); }
/// <summary> /// Asserts a <see cref="DotRas.RasNetworkProtocols"/> object. /// </summary> /// <param name="expected">The expected value.</param> /// <param name="actual">The actual value.</param> public static void AssertRasNetworkProtocols(RasNetworkProtocols expected, RasNetworkProtocols actual) { if ((expected == null && actual != null) || (expected != null && actual == null)) { Assert.Fail(); } else { Assert.AreEqual(expected.IP, actual.IP); #if (WIN2K8 || WIN7 || WIN8) Assert.AreEqual(expected.IPv6, actual.IPv6); #endif Assert.AreEqual(expected.Ipx, actual.Ipx); #pragma warning disable 0618 Assert.AreEqual(expected.NetBeui, actual.NetBeui); #pragma warning restore 0618 #if (WIN2K8 || WIN7 || WIN8) Assert.AreEqual(expected.IPv6, actual.IPv6); #endif } }
private static RasEntry CreateVpn(string vpnName, string ipAddress) { RasEntry ras = new RasEntry(vpnName) { Device = RasDevice.Create("WAN Miniport (PPTP)", RasDeviceType.Vpn), DialMode = RasDialMode.None, EncryptionType = RasEncryptionType.Optional, EntryType = RasEntryType.Vpn, FramingProtocol = RasFramingProtocol.Ppp, PhoneNumber = ipAddress, RedialCount = 2, RedialPause = 60, VpnStrategy = RasVpnStrategy.PptpOnly, Options = { DoNotNegotiateMultilink = true, IPv6RemoteDefaultGateway = true, ModemLights = true, ReconnectIfDropped = true, RemoteDefaultGateway = false, RequireDataEncryption = false, RequireEncryptedPassword = true, RequireChap = true, RequireMSChap2 = true, RequireMSEncryptedPassword = true } }; RasNetworkProtocols rasNetworkProtocols = new RasNetworkProtocols { IP = true, IPv6 = true, Ipx = false }; ras.NetworkProtocols = rasNetworkProtocols; return(ras); }