public void Lookup(IDNSRequest request, ref DomainName cloneFromZone, ref int prefixLabels, ref bool forceAA) { var tz = request.QName; var ct = 0; while (true) { if (tz == DomainName.Root) { return; } if (ToZones.ContainsKey(tz)) { cloneFromZone = FromZone; prefixLabels = ct; forceAA = false; return; } ct += 1; tz = tz.Parent(); } }
public void LookupTXT(IDNSRequest req, ref string resultText, ref int resultTTL) { throw new NotImplementedException(); }
public void Lookup(IDNSRequest req, ref IPAddress resultIP, ref int resultTTL) { resultIP = null; var HostName = req.QName.ToString().ToLower(); if (Cfg.Prefix.Length > 0 && !HostName.StartsWith(Cfg.Prefix)) return; if (!HostName.EndsWith(Cfg.Suffix)) return; var IPPart = HostName.Substring(Cfg.Prefix.Length); IPPart = IPPart.Substring(0, IPPart.Length - Cfg.Suffix.Length); if (CfgIPv6) { IPPart = IPPart.Replace("-", ""); if (!Cfg.FullIP) IPPart = HostIPMatchPrefix + IPPart; if (IPPart.Length != 32) return; IPPart = IPPart.Substring(0, 4) + ":" + IPPart.Substring(4, 4) + ":" + IPPart.Substring(8, 4) + ":" + IPPart.Substring(12, 4) + ":" + IPPart.Substring(16, 4) + ":" + IPPart.Substring(20, 4) + ":" + IPPart.Substring(24, 4) + ":" + IPPart.Substring(28, 4); if (!IPAddressV6.TryParse(IPPart, ref resultIP)) { resultIP = null; return; } } else { IPPart = IPPart.Replace("-", "."); if (!Cfg.FullIP) IPPart = HostIPMatchPrefix + "." + IPPart; if (!IPAddressV4.TryParse(IPPart, ref resultIP)) { resultIP = null; return; } } resultTTL = Cfg.TTL; }
public void LookupReverse(IDNSRequest req, ref DomainName resultName, ref int resultTTL) { resultName = null; var ipb = req.QNameIP.GetBytes(); var sn = Cfg.FullIP ? 0 : Cfg.Subnet; string x; if (CfgIPv6) { var sb = new System.Text.StringBuilder(32); for (var i = 0; i < 16; i++) sb.Append(ByteToHex2(ipb[i])); var z = sb.ToString(); if (!Cfg.FullIP) z = z.Substring(Cfg.Subnet / 4); //insert hypens instead of colons x = ""; int p; while (z.Length > 0) { if (x.Length > 0) x = "-" + x; if (z.Length <= 4) p = 0; else p = z.Length - 4; x = z.Substring(p) + x; z = z.Substring(0, p); } } else { //IPv4 x = ipb[3].ToString(); if (sn <= 16) x = ipb[2].ToString() + "-" + x; if (sn <= 8) x = ipb[1].ToString() + "-" + x; if (sn == 0) x = ipb[0].ToString() + "-" + x; } resultName = DomainName.Parse(Cfg.Prefix + x + Cfg.Suffix); resultTTL = Cfg.TTL; }