Ejemplo n.º 1
0
        //---------------------------------------------------------------------
        // Static members

        /// <summary>
        /// Loads settings from the application configuration.
        /// </summary>
        /// <param name="keyPrefix">The configuration key prefix.</param>
        /// <returns>A <see cref="DnsServerSettings" /> instance.</returns>
        /// <remarks>
        /// <para>
        /// This method loads the following settings from the application
        /// configuration:
        /// </para>
        /// <div class="tablediv">
        /// <table class="dtTABLE" cellspacing="0" ID="Table1">
        /// <tr valign="top">
        /// <th width="1">Setting</th>
        /// <th width="1">Default</th>
        /// <th width="90%">Description</th>
        /// </tr>
        /// <tr valign="top">
        ///     <td>NetworkBinding</td>
        ///     <td>ANY:DNS</td>
        ///     <td>
        ///     Specifies the <see cref="NetworkBinding" /> the server should listen on.
        ///     </td>
        ///  </tr>
        /// </table>
        /// </div>
        /// </remarks>
        public static DnsServerSettings LoadConfig(string keyPrefix)
        {
            Config            config;
            DnsServerSettings settings;

            config   = new Config(keyPrefix);
            settings = new DnsServerSettings();
            settings.NetworkBinding = config.Get("NetworkBinding", settings.NetworkBinding);

            return(settings);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts the DNS server using the settings passed.
        /// </summary>
        /// <param name="settings">The <see cref="DnsServerSettings" /> to be used to initialize the server.</param>
        /// <exception cref="InvalidOperationException">Thrown if the server has already started.</exception>
        public void Start(DnsServerSettings settings)
        {
            lock (syncLock)
            {
                if (sock != null)
                {
                    throw new InvalidOperationException("DNS server has already started.");
                }

                sock = new EnhancedSocket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                sock.IgnoreUdpConnectionReset = true;
                sock.ReceiveBufferSize        =
                    sock.ReceiveBufferSize    = 1024 * 1024;  // $todo(jeff.lill): Hardcoded
                sock.Bind(settings.NetworkBinding);

                remoteEP = new IPEndPoint(IPAddress.Any, 0);
                sock.BeginReceiveFrom(recvBuf, 0, recvBuf.Length, SocketFlags.None, ref remoteEP, onReceive, sock);
            }
        }