Пример #1
0
        public static Hashtable QueryConfig()
        {
            Hashtable items = new Hashtable();

            HttpApi.HTTP_SERVICE_CONFIG_SSL_QUERY query = new HttpApi.HTTP_SERVICE_CONFIG_SSL_QUERY();

            query.QueryDesc = HttpApi.HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryNext;

            IntPtr pInput = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HttpApi.HTTP_SERVICE_CONFIG_SSL_QUERY)));

            try
            {
                for (query.dwToken = 0; ; query.dwToken++)
                {
                    Marshal.StructureToPtr(query, pInput, false);

                    int requiredBufferLength = 0;

                    HttpApi.Error error = QueryServiceConfig(pInput, IntPtr.Zero, 0, out requiredBufferLength);

                    if (error == HttpApi.Error.ERROR_NO_MORE_ITEMS)
                    {
                        break;
                    }
                    else if (error != HttpApi.Error.ERROR_INSUFFICIENT_BUFFER)
                    {
                        throw new HttpApiException(error, "HttpQueryServiceConfiguration (SSL) failed.  Error = " + error);
                    }

                    IntPtr pOutput = Marshal.AllocHGlobal(requiredBufferLength);

                    try
                    {
                        HttpApi.ZeroMemory(pOutput, requiredBufferLength);

                        error = QueryServiceConfig(pInput, pOutput, requiredBufferLength, out requiredBufferLength);

                        if (error != HttpApi.Error.NO_ERROR)
                        {
                            throw new HttpApiException(error, "HttpQueryServiceConfiguration (SSL) failed.  Error = " + error);
                        }

                        SslConfigItem item = Deserialize(pOutput);

                        items.Add(item.Key, item);
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(pOutput);
                    }
                }
            }
            finally
            {
                Marshal.FreeHGlobal(pInput);
            }

            return(items);
        }
Пример #2
0
        public static Hashtable QueryConfig()
        {
            Hashtable items = new Hashtable();

            int requiredBufferLength = 0;

            HttpApi.Error error = QueryServiceConfig(IntPtr.Zero, 0, out requiredBufferLength);

            if ((error != HttpApi.Error.ERROR_FILE_NOT_FOUND) && (error != HttpApi.Error.ERROR_NOT_FOUND))
            {
                if (error != HttpApi.Error.ERROR_INSUFFICIENT_BUFFER)
                {
                    throw new HttpApiException(error, "HttpQueryServiceConfiguration (IPLISTEN) failed.  Error = " + error);
                }

                IntPtr pOutput = Marshal.AllocHGlobal(requiredBufferLength);

                try
                {
                    HttpApi.ZeroMemory(pOutput, requiredBufferLength);

                    error = QueryServiceConfig(pOutput, requiredBufferLength, out requiredBufferLength);

                    if (error != HttpApi.Error.NO_ERROR)
                    {
                        throw new HttpApiException(error, "HttpQueryServiceConfiguration (IPLISTEN) failed.  Error = " + error);
                    }

                    HttpApi.HTTP_SERVICE_CONFIG_IP_LISTEN_QUERY output =
                        (HttpApi.HTTP_SERVICE_CONFIG_IP_LISTEN_QUERY)Marshal.PtrToStructure(pOutput, typeof(HttpApi.HTTP_SERVICE_CONFIG_IP_LISTEN_QUERY));

                    int addrSize = Marshal.SizeOf(typeof(HttpApi.SOCKADDR_STORAGE));

                    IntPtr pAddress = HttpApi.IncIntPtr(pOutput, 8); // Increment past the addrcount member and padding

                    for (int i = 0; i < output.AddrCount; i++)
                    {
                        IpListenConfigItem item = new IpListenConfigItem();

                        item.Address = new IPAddress((long)Marshal.ReadInt32(pAddress, 4) & 0x00000000ffffffff);

                        item.Status = ModifiedStatus.Unmodified;

                        items.Add(item.Key, item);

                        pAddress = HttpApi.IncIntPtr(pAddress, addrSize); // Increment to the next IP address
                    }
                }
                finally
                {
                    Marshal.FreeHGlobal(pOutput);
                }
            }

            return(items);
        }
Пример #3
0
        public static IntPtr BuildSockaddr(short family, ushort port, IPAddress address)
        {
            int sockaddrSize = Marshal.SizeOf(typeof(HttpApi.sockaddr));

            IntPtr pSockaddr = Marshal.AllocHGlobal(sockaddrSize);

            HttpApi.ZeroMemory(pSockaddr, sockaddrSize);

            Marshal.WriteInt16(pSockaddr, family);

            ushort p = (ushort)IPAddress.HostToNetworkOrder((short)port);

            Marshal.WriteInt16(pSockaddr, 2, (short)p);

            byte[] addr = address.GetAddressBytes();

            IntPtr pAddr = HttpApi.IncIntPtr(pSockaddr, 4);

            Marshal.Copy(addr, 0, pAddr, addr.Length);

            return(pSockaddr);
        }