public void Start() { var configFile = Assembly.GetEntryAssembly().Location; configFile = Path.Combine(Path.GetDirectoryName(configFile), "dns.config.xml"); var config = DnsConfig.LoadFromXmlFile(configFile); _dnsManager = new DnsManager(config); _dnsServer = new DnsServer(10, 10); _dnsServer.QueryReceived += OnQueryReceived; _dnsServer.Start(); }
public DnsManager(DnsConfig config) { if (config == null) { throw new ArgumentNullException(@"config"); } var clients = new Dictionary <string, DnsClient>(); foreach (var it in config.Clients) { var client = new DnsClient(it.IPAddresses.Select(ip => IPAddress.Parse(ip)), it.QueryTimeout); if ("default".Equals(it.Id, StringComparison.OrdinalIgnoreCase)) { _defaultDnsClient = client; } clients[it.Id] = client; } foreach (var item in config.Mappings) { _domainToDnsClient[item.Match] = clients.TryGetValue(item.ClientId); } }