/// <summary> /// Sets the options on a <see cref="RasIkeV2Options"/> for the flags specified. /// </summary> /// <param name="options">The options to set.</param> /// <param name="value">The flags of the entry.</param> /// <exception cref="System.ArgumentNullException"><paramref name="options"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception> public static void SetRasIkeV2Options(RasIkeV2Options options, NativeMethods.RASIKEV2 value) { if (options != null) { options.MobileIke = Utilities.HasFlag(value, NativeMethods.RASIKEV2.MobileIke); options.ClientBehindNat = Utilities.HasFlag(value, NativeMethods.RASIKEV2.ClientBehindNat); options.ServerBehindNat = Utilities.HasFlag(value, NativeMethods.RASIKEV2.ServerBehindNat); } }
public object GetProjectionInfoEx(RasHandle handle) { object retval = null; int size = Marshal.SizeOf(typeof(NativeMethods.RAS_PROJECTION_INFO)); IntPtr lpdwSize = new IntPtr(size); bool retry = false; do { NativeMethods.RAS_PROJECTION_INFO projectionInfo = new NativeMethods.RAS_PROJECTION_INFO(); projectionInfo.version = GetCurrentApiVersion(); IntPtr pRasProjection = IntPtr.Zero; try { pRasProjection = Marshal.AllocHGlobal(lpdwSize); Marshal.StructureToPtr(projectionInfo, pRasProjection, true); int ret = SafeNativeMethods.Instance.GetProjectionInfoEx(handle, pRasProjection, ref lpdwSize); if (ret == NativeMethods.ERROR_BUFFER_TOO_SMALL) { retry = true; } else if (ret == NativeMethods.SUCCESS) { projectionInfo = Utilities.PtrToStructure<NativeMethods.RAS_PROJECTION_INFO>(pRasProjection); // Use the object located at the end of the structure since the union will cause portability issues on 64-bit platforms. IntPtr pInfo = new IntPtr(pRasProjection.ToInt64() + size); switch (projectionInfo.type) { case NativeMethods.RASPROJECTION_INFO_TYPE.Ppp: NativeMethods.RASPPP_PROJECTION_INFO ppp = Utilities.PtrToStructure<NativeMethods.RASPPP_PROJECTION_INFO>(pInfo); ReadOnlyCollection<byte> interfaceIdentifier = null; if (ppp.interfaceIdentifier != null && ppp.interfaceIdentifier.Length > 0) { interfaceIdentifier = new ReadOnlyCollection<byte>(new List<byte>(ppp.interfaceIdentifier)); } ReadOnlyCollection<byte> serverInterfaceIdentifier = null; if (ppp.serverInterfaceIdentifier != null && ppp.serverInterfaceIdentifier.Length > 0) { serverInterfaceIdentifier = new ReadOnlyCollection<byte>(new List<byte>(ppp.serverInterfaceIdentifier)); } retval = new RasPppInfo( ppp.ipv4NegotiationError, new IPAddress(ppp.ipv4Address.addr), new IPAddress(ppp.ipv4ServerAddress.addr), ppp.ipv4Options, ppp.ipv4ServerOptions, ppp.ipv6NegotiationError, interfaceIdentifier, serverInterfaceIdentifier, ppp.bundled, ppp.multilink, ppp.authenticationProtocol, ppp.authenticationData, ppp.serverAuthenticationProtocol, ppp.serverAuthenticationData, ppp.eapTypeId, ppp.serverEapTypeId, new RasLcpOptions(ppp.lcpOptions), new RasLcpOptions(ppp.serverLcpOptions), ppp.ccpCompressionAlgorithm, ppp.serverCcpCompressionAlgorithm, new RasCompressionOptions(ppp.ccpOptions), new RasCompressionOptions(ppp.serverCcpOptions)); break; case NativeMethods.RASPROJECTION_INFO_TYPE.IkeV2: NativeMethods.RASIKEV2_PROJECTION_INFO ikev2 = Utilities.PtrToStructure<NativeMethods.RASIKEV2_PROJECTION_INFO>(pInfo); RasIkeV2Options ikev2Options = new RasIkeV2Options(); Utilities.SetRasIkeV2Options(ikev2Options, ikev2.options); retval = new RasIkeV2Info( ikev2.ipv4NegotiationError, new IPAddress(ikev2.ipv4Address.addr), new IPAddress(ikev2.ipv4ServerAddress.addr), ikev2.ipv6NegotiationError, new IPAddress(ikev2.ipv6Address.addr), new IPAddress(ikev2.ipv6ServerAddress.addr), ikev2.prefixLength, ikev2.authenticationProtocol, ikev2.eapTypeId, ikev2Options, ikev2.encryptionMethod, Utilities.CreateIPv4AddressCollection(ikev2.ipv4ServerAddresses, ikev2.numIPv4ServerAddresses), Utilities.CreateIPv6AddressCollection(ikev2.ipv6ServerAddresses, ikev2.numIPv6ServerAddresses)); break; } retry = false; } else { ThrowHelper.ThrowRasException(ret); } } catch (EntryPointNotFoundException) { ThrowHelper.ThrowNotSupportedException(Resources.Exception_NotSupportedOnPlatform); } finally { if (pRasProjection != IntPtr.Zero) { Marshal.FreeHGlobal(pRasProjection); } } } while (retry); return retval; }