Exemplo n.º 1
0
        public void RasCcpInfoConstructorTest()
        {
            var errorCode            = int.MaxValue;
            var compressionAlgorithm = RasCompressionType.Mppc;
            var options = new RasCompressionOptions(NativeMethods.RASCCPO.Encryption128Bit);
            var serverCompressionAlgorithm = RasCompressionType.Stac;
            var serverOptions = new RasCompressionOptions(NativeMethods.RASCCPO.Encryption40Bit);

            var target = new RasCcpInfo(errorCode, compressionAlgorithm, options, serverCompressionAlgorithm, serverOptions);

            Assert.IsNotNull(target);
        }
Exemplo n.º 2
0
        public void OptionsTest()
        {
            var errorCode                  = int.MaxValue;
            var compressionAlgorithm       = RasCompressionType.Mppc;
            var expected                   = new RasCompressionOptions(NativeMethods.RASCCPO.Encryption128Bit);
            var serverCompressionAlgorithm = RasCompressionType.Stac;
            var serverOptions              = new RasCompressionOptions(NativeMethods.RASCCPO.Encryption40Bit);

            var target = new RasCcpInfo(errorCode, compressionAlgorithm, expected, serverCompressionAlgorithm, serverOptions);

            RasCompressionOptions actual;

            actual = target.Options;

            Assert.AreSame(expected, actual);
        }
Exemplo n.º 3
0
        public void ErrorCodeTest()
        {
            var errorCode            = int.MaxValue;
            var compressionAlgorithm = RasCompressionType.Mppc;
            var options = new RasCompressionOptions(NativeMethods.RASCCPO.Encryption128Bit);
            var serverCompressionAlgorithm = RasCompressionType.Stac;
            var serverOptions = new RasCompressionOptions(NativeMethods.RASCCPO.Encryption40Bit);

            var target = new RasCcpInfo(errorCode, compressionAlgorithm, options, serverCompressionAlgorithm, serverOptions);

            int actual;

            actual = target.ErrorCode;

            Assert.AreEqual(errorCode, actual);
        }
Exemplo n.º 4
0
        public void ServerCompressionAlgorithmTest()
        {
            int errorCode = int.MaxValue;
            RasCompressionType    compressionAlgorithm = RasCompressionType.Mppc;
            RasCompressionOptions options       = new RasCompressionOptions(NativeMethods.RASCCPO.Encryption128Bit);
            RasCompressionType    expected      = RasCompressionType.Stac;
            RasCompressionOptions serverOptions = new RasCompressionOptions(NativeMethods.RASCCPO.Encryption40Bit);

            RasCcpInfo target = new RasCcpInfo(errorCode, compressionAlgorithm, options, expected, serverOptions);

            RasCompressionType actual;

            actual = target.ServerCompressionAlgorithm;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 5
0
        public void GetProjectionInfoCcpTest()
        {
            var expected = new RasCcpInfo(
                0,
                RasCompressionType.None,
                new RasCompressionOptions(NativeMethods.RASCCPO.None),
                RasCompressionType.None,
                new RasCompressionOptions(NativeMethods.RASCCPO.None));

            var mock = new Mock <IRasHelper>();

            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.GetProjectionInfo(It.IsAny <RasHandle>(), NativeMethods.RASPROJECTION.Ccp)).Returns(expected);

            var target = new RasConnection();
            var actual = (RasCcpInfo)target.GetProjectionInfo(RasProjectionType.Ccp);

            Assert.AreSame(expected, actual);
        }
Exemplo n.º 6
0
        public object GetProjectionInfo(RasHandle handle, NativeMethods.RASPROJECTION projection)
        {
            if (Utilities.IsHandleInvalidOrClosed(handle))
            {
                ThrowHelper.ThrowArgumentException("handle", Resources.Argument_InvalidHandle);
            }

            int size = 0;

            object retval = null;
            object structure = null;

            switch (projection)
            {
                case NativeMethods.RASPROJECTION.Amb:
                    size = Marshal.SizeOf(typeof(NativeMethods.RASAMB));

                    NativeMethods.RASAMB amb = new NativeMethods.RASAMB();
                    amb.size = size;

                    structure = amb;
                    break;

                case NativeMethods.RASPROJECTION.Ccp:
                    size = Marshal.SizeOf(typeof(NativeMethods.RASPPPCCP));

                    NativeMethods.RASPPPCCP ccp = new NativeMethods.RASPPPCCP();
                    ccp.size = size;

                    structure = ccp;
                    break;

                case NativeMethods.RASPROJECTION.IP:
                    size = Marshal.SizeOf(typeof(NativeMethods.RASPPPIP));

                    NativeMethods.RASPPPIP ip = new NativeMethods.RASPPPIP();
                    ip.size = size;

                    structure = ip;
                    break;

                case NativeMethods.RASPROJECTION.Ipx:
                    size = Marshal.SizeOf(typeof(NativeMethods.RASPPPIPX));

                    NativeMethods.RASPPPIPX ipx = new NativeMethods.RASPPPIPX();
                    ipx.size = size;

                    structure = ipx;
                    break;

                case NativeMethods.RASPROJECTION.Lcp:
                    size = Marshal.SizeOf(typeof(NativeMethods.RASPPPLCP));

                    NativeMethods.RASPPPLCP lcp = new NativeMethods.RASPPPLCP();
                    lcp.size = size;

                    structure = lcp;
                    break;

                case NativeMethods.RASPROJECTION.Nbf:
                    size = Marshal.SizeOf(typeof(NativeMethods.RASPPPNBF));

                    NativeMethods.RASPPPNBF nbf = new NativeMethods.RASPPPNBF();
                    nbf.size = size;

                    structure = nbf;
                    break;

#if (WIN2K8 || WIN7 || WIN8)

                case NativeMethods.RASPROJECTION.IPv6:
                    size = Marshal.SizeOf(typeof(NativeMethods.RASPPPIPV6));

                    NativeMethods.RASPPPIPV6 ipv6 = new NativeMethods.RASPPPIPV6();
                    ipv6.size = size;

                    structure = ipv6;
                    break;

#endif
                case NativeMethods.RASPROJECTION.Slip:
                    size = Marshal.SizeOf(typeof(NativeMethods.RASSLIP));

                    NativeMethods.RASSLIP slip = new NativeMethods.RASSLIP();
                    slip.size = size;

                    structure = slip;
                    break;
            }

            IntPtr lpCb = new IntPtr(size);

            IntPtr lpProjection = IntPtr.Zero;
            try
            {
                lpProjection = Marshal.AllocHGlobal(lpCb);
                Marshal.StructureToPtr(structure, lpProjection, true);

                int ret = SafeNativeMethods.Instance.GetProjectionInfo(handle, projection, lpProjection, ref lpCb);
                if (ret == NativeMethods.SUCCESS)
                {
                    IPAddressConverter converter = new IPAddressConverter();

                    switch (projection)
                    {
                        case NativeMethods.RASPROJECTION.Amb:
                            NativeMethods.RASAMB amb = Utilities.PtrToStructure<NativeMethods.RASAMB>(lpProjection);

                            retval = new RasAmbInfo(
                                amb.errorCode,
                                amb.netBiosError,
                                amb.lana);

                            break;

                        case NativeMethods.RASPROJECTION.Ccp:
                            NativeMethods.RASPPPCCP ccp = Utilities.PtrToStructure<NativeMethods.RASPPPCCP>(lpProjection);

                            retval = new RasCcpInfo(
                                ccp.errorCode,
                                ccp.compressionAlgorithm,
                                new RasCompressionOptions(ccp.options),
                                ccp.serverCompressionAlgorithm,
                                new RasCompressionOptions(ccp.serverOptions));

                            break;

                        case NativeMethods.RASPROJECTION.IP:
                            NativeMethods.RASPPPIP ip = Utilities.PtrToStructure<NativeMethods.RASPPPIP>(lpProjection);

                            retval = new RasIPInfo(
                                ip.errorCode,
                                (IPAddress)converter.ConvertFrom(ip.ipAddress),
                                (IPAddress)converter.ConvertFrom(ip.serverIPAddress),
                                new RasIPOptions(ip.options),
                                new RasIPOptions(ip.serverOptions));

                            break;

                        case NativeMethods.RASPROJECTION.Ipx:
                            NativeMethods.RASPPPIPX ipx = Utilities.PtrToStructure<NativeMethods.RASPPPIPX>(lpProjection);

                            retval = new RasIpxInfo(
                                ipx.errorCode,
                                (IPAddress)converter.ConvertFrom(ipx.ipxAddress));

                            break;

                        case NativeMethods.RASPROJECTION.Lcp:
                            NativeMethods.RASPPPLCP lcp = Utilities.PtrToStructure<NativeMethods.RASPPPLCP>(lpProjection);

                            retval = new RasLcpInfo(
                                lcp.bundled,
                                lcp.errorCode,
                                lcp.authenticationProtocol,
                                lcp.authenticationData,
                                lcp.eapTypeId,
                                lcp.serverAuthenticationProtocol,
                                lcp.serverAuthenticationData,
                                lcp.serverEapTypeId,
                                lcp.multilink,
                                lcp.terminateReason,
                                lcp.serverTerminateReason,
                                lcp.replyMessage,
                                new RasLcpOptions(lcp.options),
                                new RasLcpOptions(lcp.serverOptions));

                            break;

                        case NativeMethods.RASPROJECTION.Nbf:
                            NativeMethods.RASPPPNBF nbf = Utilities.PtrToStructure<NativeMethods.RASPPPNBF>(lpProjection);

                            retval = new RasNbfInfo(
                                nbf.errorCode,
                                nbf.netBiosErrorCode,
                                nbf.netBiosErrorMessage,
                                nbf.workstationName,
                                nbf.lana);

                            break;

                        case NativeMethods.RASPROJECTION.Slip:
                            NativeMethods.RASSLIP slip = Utilities.PtrToStructure<NativeMethods.RASSLIP>(lpProjection);

                            retval = new RasSlipInfo(
                                slip.errorCode,
                                (IPAddress)converter.ConvertFrom(slip.ipAddress));

                            break;

#if (WIN2K8 || WIN7 || WIN8)
                        case NativeMethods.RASPROJECTION.IPv6:
                            NativeMethods.RASPPPIPV6 ipv6 = Utilities.PtrToStructure<NativeMethods.RASPPPIPV6>(lpProjection);

                            retval = new RasIPv6Info(
                                ipv6.errorCode,
                                Utilities.ConvertBytesToInt64(ipv6.localInterfaceIdentifier, 0),
                                Utilities.ConvertBytesToInt64(ipv6.peerInterfaceIdentifier, 0),
                                Utilities.ConvertBytesToInt16(ipv6.localCompressionProtocol, 0),
                                Utilities.ConvertBytesToInt16(ipv6.peerCompressionProtocol, 0));

                            break;
#endif
                    }
                }
                else if (ret != NativeMethods.ERROR_INVALID_PARAMETER && ret != NativeMethods.ERROR_PROTOCOL_NOT_CONFIGURED)
                {
                    ThrowHelper.ThrowRasException(ret);
                }
            }
            catch (EntryPointNotFoundException)
            {
                ThrowHelper.ThrowNotSupportedException(Resources.Exception_NotSupportedOnPlatform);
            }
            finally
            {
                if (lpProjection != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(lpProjection);
                }
            }

            return retval;
        }