Пример #1
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);
        }
Пример #2
0
        private void addIpListenerButton_Click(object sender, System.EventArgs e)
        {
            try
            {
                using (InputBox input = new InputBox("New IP Listener", "Please enter an IP Address"))
                {
                    if (input.ShowDialog(this) == DialogResult.OK)
                    {
                        IPAddress address = IPAddress.Parse(input.UserInput);

                        IpListenConfigItem newItem = new IpListenConfigItem();

                        newItem.Address = address;

                        newItem.Status = ModifiedStatus.Added;

                        if (_ipListenItems.Contains(newItem.Key))
                        {
                            MessageBox.Show(this, "The IP address you entered is already configured.", "Invalid Input");
                        }
                        else
                        {
                            _ipListenItems.Add(newItem.Key, newItem);

                            ipListenersListView.Items.Add(newItem);

                            applyButton.Enabled = true;
                        }
                    }
                }
            }
            catch (FormatException)
            {
                MessageBox.Show(this, "The data you entered was not formatted correctly.  Please enter a correctly formatted IP address.", "Invalid Input");
            }
            catch (Exception ex)
            {
                DisplayError(ex);
            }
            finally
            {
                removeIpListenerButton.Enabled = ipListenersListView.SelectedItems.Count > 0;
            }
        }
Пример #3
0
        private void Load_IpListenItems()
        {
            _ipListenItems = IpListenConfigItem.QueryConfig();

            PopulateConfigListView(_ipListenItems, ipListenersListView);
        }