/// <summary> /// Construct the question from parameters, checking for safety /// </summary> /// <param name="domain">the domain name to query eg. bigdevelopments.co.uk</param> /// <param name="dnsType">the QTYPE of query eg. DnsType.MX</param> /// <param name="dnsClass">the CLASS of query, invariably DnsClass.IN</param> public Question(string domain, DnsType dnsType, DnsClass dnsClass) { // check the input parameters if (domain == null) { throw new ArgumentNullException("domain"); } // do a sanity check on the domain name to make sure its legal if (domain.Length == 0 || domain.Length > 255 || !Regex.IsMatch(domain, @"^[a-z|A-Z|0-9|\-|_]{1,63}(\.[a-z|A-Z|0-9|-|_]{1,63})+$")) { // domain names can't be bigger tan 255 chars, and individal labels can't be bigger than 63 chars throw new ArgumentException("The supplied domain name was not in the correct form", "domain"); } // sanity check the DnsType parameter if (!Enum.IsDefined(typeof(DnsType), dnsType) || dnsType == DnsType.None) { throw new ArgumentOutOfRangeException("dnsType", "Not a valid value"); } // sanity check the DnsClass parameter if (!Enum.IsDefined(typeof(DnsClass), dnsClass) || dnsClass == DnsClass.None) { throw new ArgumentOutOfRangeException("dnsClass", "Not a valid value"); } // just remember the values _domain = domain; _dnsType = dnsType; _dnsClass = dnsClass; }
/// <summary> /// Construct a resource record from a pointer to a byte array /// </summary> /// <param name="pointer">the position in the byte array of the record</param> internal ResourceRecord(Pointer pointer) { // extract the domain, question type, question class and Ttl _domain = pointer.ReadDomain(); _dnsType = (DnsType)pointer.ReadShort(); _dnsClass = (DnsClass)pointer.ReadShort(); _Ttl = pointer.ReadInt(); // the next short is the record length, we only use it for unrecognised record types int recordLength = pointer.ReadShort(); // and create the appropriate RDATA record based on the dnsType switch (_dnsType) { case DnsType.NS: _record = new NSRecord(pointer); break; case DnsType.MX: _record = new MXRecord(pointer); break; case DnsType.ANAME: _record = new ANameRecord(pointer); break; case DnsType.SOA: _record = new SoaRecord(pointer); break; default: { // move the pointer over this unrecognised record pointer += recordLength; break; } } }
/// <summary> /// Construct the question reading from a DNS Server response. Consult RFC1035 4.1.2 /// for byte-wise details of this structure in byte array form /// </summary> /// <param name="pointer">a logical pointer to the Question in byte array form</param> internal Question(Pointer pointer) { // extract from the message _domain = pointer.ReadDomain(); _dnsType = (DnsType)pointer.ReadShort(); _dnsClass = (DnsClass)pointer.ReadShort(); }
/// <summary> /// Construct a resource record from a pointer to a byte array /// </summary> /// <param name="pointer">the position in the byte array of the record</param> internal ResourceRecord(Pointer pointer) { // extract the domain, question type, question class and Ttl this._domain = pointer.ReadDomain(); this._dnsType = (DnsType)pointer.ReadShort(); this._dnsClass = (DnsClass)pointer.ReadShort(); this._Ttl = pointer.ReadInt(); // the next short is the record length, we only use it for unrecognised record types int recordLength = pointer.ReadShort(); // and create the appropriate RDATA record based on the dnsType switch (this._dnsType) { case DnsType.SRV: this._record = new SRVRecord(pointer); break; default: { // move the pointer over this unrecognised record pointer.Position += recordLength; break; } } }
public Query(string domain, DnsType type, DnsClass dnsClass) { RLog log = new RLog(); log.log("Query.cs", "Setting up query: " + domain, ELogLevel.Info3); if (domain == null) { throw new ArgumentNullException("domain"); } if (domain.Length == 0 || domain.Length > 255 || !Regex.IsMatch(domain, @"^[a-z|A-Z|0-9|-|_]{1,63}(\.[a-z|A-Z|0-9|-|_]{1,63})+$")) { log.log("Query.cs", "Domain is of incorrect type", ELogLevel.Fatal0); throw new ArgumentException("Domain is of incorrect type"); } if (!Enum.IsDefined(typeof(DnsType), type) || type == DnsType.None) { log.log("Query.cs", "DNS TYPE is out of range", ELogLevel.Fatal0); throw new ArgumentException(); } if (!Enum.IsDefined(typeof(DnsClass), dnsClass) || dnsClass == DnsClass.None) { log.log("Query.cs", "DNS CLASS is out of range", ELogLevel.Fatal0); throw new ArgumentException(); } _domain = domain; _dnsType = type; _dnsClass = dnsClass; }
/// <summary> /// Construct a resource record from a pointer to a byte array /// </summary> /// <param name="pointer">the position in the byte array of the record</param> internal ResourceRecord(Pointer pointer) { // extract the domain, question type, question class and Ttl _domain = pointer.ReadDomain(); _dnsType = (DnsType)pointer.ReadShort(); _dnsClass = (DnsClass)pointer.ReadShort(); _Ttl = pointer.ReadInt(); // the next short is the record length, we only use it for unrecognised record types int recordLength = pointer.ReadShort(); // and create the appropriate RDATA record based on the dnsType switch(_dnsType) { case DnsType.NS: _record = new NSRecord(pointer); break; case DnsType.MX: _record = new MXRecord(pointer); break; case DnsType.ANAME: _record = new ANameRecord(pointer); break; case DnsType.SOA: _record = new SoaRecord(pointer); break; default: { // move the pointer over this unrecognised record pointer += recordLength; break; } } }
public DnsQuestion(NetBinaryReader nbr) { List<string> labels = new List<string>(); byte nameLength; while ((nameLength = nbr.ReadByte()) != 0) { string label = string.Empty; for (int i = 0; i < nameLength; i++) { label += (char)nbr.ReadByte(); } labels.Add(label); } QueriedDomainName = string.Join(".", labels); Type = (QType)nbr.ReadUInt16(); ushort rawClass = nbr.ReadUInt16(); if (rawClass > 65279) rawClass = 0; else if (rawClass > 4 && rawClass < 252) rawClass = 2; else if (rawClass > 255 && rawClass < 65280) rawClass = 2; Class = (DnsClass)rawClass; }
/// <summary> /// Construct the question reading from a DNS Server response. Consult RFC1035 4.1.2 /// for byte-wise details of this structure in byte array form /// </summary> /// <param name="pointer"> a logical pointer to the Question in byte array form </param> public Question(Pointer pointer) { // extract from the message this._domain = pointer.ReadDomain(); this._dnsType = (DnsType) pointer.ReadShort(); this._dnsClass = (DnsClass) pointer.ReadShort(); }
public Question(string domain, Type recordType, DnsClass dnsClass) { DnsType dnsType = DnsType.None; if (recordType == typeof(ANameRecord)) { dnsType = DnsType.ANAME; } if (recordType == typeof(SoaRecord)) { dnsType = DnsType.SOA; } if (recordType == typeof(MXRecord)) { dnsType = DnsType.MX; } if (recordType == typeof(NSRecord)) { dnsType = DnsType.NS; } CheckParams(domain, dnsType, dnsClass); _domain = domain; _dnsType = dnsType; _dnsClass = dnsClass; }
public Question(string domain, DnsType qtype, DnsClass qclass) { if (qtype == DnsType.PTR) { IPAddress addr = IPAddress.Parse(domain); StringBuilder sb = new StringBuilder(); byte[] addrBytes = addr.GetAddressBytes(); for (int i = addrBytes.Length - 1; i >= 0; i--) { sb.Append((int)addrBytes[i] + "."); } sb.Append("in-addr.arpa"); _domain = sb.ToString(); } else { _domain = domain; } _qtype = qtype; _qclass = qclass; }
public DnsQuestionRecord(IPAddress ip, DnsClass @class) { _type = DnsResourceRecordType.PTR; _class = @class; byte[] ipBytes = ip.GetAddressBytes(); switch (ip.AddressFamily) { case AddressFamily.InterNetwork: for (int i = ipBytes.Length - 1; i >= 0; i += -1) { _name += ipBytes[i] + "."; } _name += "IN-ADDR.ARPA"; break; case AddressFamily.InterNetworkV6: for (int i = ipBytes.Length - 1; i >= 0; i += -1) { _name += (ipBytes[i] & 0x0F).ToString("X") + "." + (ipBytes[i] >> 4).ToString("X") + "."; } _name += "IP6.ARPA"; break; default: throw new DnsClientException("IP address family not supported for PTR query."); } }
public DnsQuestion(string domain, DnsType dnsType, DnsClass dnsClass) { if (domain == null) { throw new ArgumentNullException("domain"); } if (domain.Length == 0 || domain.Length > 255 || !Regex.IsMatch(domain, @"^[a-zA-Z0-9-_]{1,63}(\.[a-zA-Z0-9-_]{1,63})+$")) { throw new ArgumentException("The supplied domain name was not in the correct form", "domain"); } if (!Enum.IsDefined(typeof(DnsType), dnsType)) { throw new ArgumentOutOfRangeException("dnsType", "Not a valid value"); } if (!Enum.IsDefined(typeof(DnsClass), dnsClass) || dnsClass == DnsClass.None) { throw new ArgumentOutOfRangeException("dnsClass", "Not a valid value"); } Domain = domain; Type = dnsType; Class = dnsClass; }
/// <summary> /// Initializes a new instance_ of the Question class by using the specified domain and dns type and class. /// </summary> /// <param name="domain">The DNS domain of the question.</param> /// <param name="dns_type">The DNS type of the question.</param> /// <param name="dns_class">The DNS class of the question.</param> public Question(string domain, DnsType dns_type, DnsClass dns_class) { if (domain == null) { throw new ArgumentNullException("domain"); } // sanity check on the domain name to make sure its legal. // domain names can't be bigger than 255 chars, and individual labels can't be bigger // than 63 chars. if (domain.Length == 0 || domain.Length > 255 || !Regex.IsMatch(domain, @"^[a-z|A-Z|0-9|-|_]{1,63}(\.[a-z|A-Z|0-9|-|_]{1,63})+$")) { throw new ArgumentException(Resources.MailChecker_InvDomain, "domain"); } // sanity check the DnsType. Only support MX. if (dns_type != DnsType.MX) { throw new ArgumentOutOfRangeException("dns_type", StringResources.Arg_OutOfRange); } // sanity check the DnsClass if ((dns_class != DnsClass.IN && dns_class != DnsClass.HS && dns_class != DnsClass.CS && dns_class != DnsClass.CH) || dns_class == DnsClass.NONE) { throw new ArgumentOutOfRangeException("dns_class", StringResources.Arg_OutOfRange); } domain_ = domain; dns_class_ = dns_class; dns_type_ = dns_type; }
/// <summary> /// Construct the question from parameters, checking for safety /// </summary> /// <param name="domain">the domain name to query eg. bigdevelopments.co.uk</param> /// <param name="dnsType">the QTYPE of query eg. DnsType.MX</param> /// <param name="dnsClass">the CLASS of query, invariably DnsClass.IN</param> public Question(string domain, DnsType dnsType, DnsClass dnsClass) { // check the input parameters if (domain == null) throw new ArgumentNullException("domain"); // do a sanity check on the domain name to make sure its legal if (domain.Length ==0 || domain.Length>255 || !Regex.IsMatch(domain, @"^[a-z|A-Z|0-9|\-|_]{1,63}(\.[a-z|A-Z|0-9|\-|_]{1,63})+$")) { // domain names can't be bigger tan 255 chars, and individal labels can't be bigger than 63 chars throw new ArgumentException("The supplied domain name was not in the correct form", "domain"); } // sanity check the DnsType parameter if (!Enum.IsDefined(typeof(DnsType), dnsType) || dnsType == DnsType.None) { throw new ArgumentOutOfRangeException("dnsType"); } // sanity check the DnsClass parameter if (!Enum.IsDefined(typeof(DnsClass), dnsClass) || dnsClass == DnsClass.None) { throw new ArgumentOutOfRangeException("dnsClass"); } // just remember the values _domain = domain; _dnsType = dnsType; _dnsClass = dnsClass; }
/// <summary> /// Construct the question reading from a DNS Server response. Consult RFC1035 4.1.2 /// for byte-wise details of this structure in byte array form /// </summary> /// <param name="pointer"> a logical pointer to the Question in byte array form </param> public Question(Pointer pointer) { // extract from the message this._domain = pointer.ReadDomain(); this._dnsType = (DnsType)pointer.ReadShort(); this._dnsClass = (DnsClass)pointer.ReadShort(); }
/// <summary> /// Construct the question reading from a DNS Server response. /// </summary> /// <param name="pointer">A logical pointer to the Question in byte array form.</param> internal Question(RecordPointer pointer) { // extract from the pointer domain_ = pointer.GetDomain(); dns_type_ = (DnsType)pointer.GetShort(); dns_class_ = (DnsClass)pointer.GetShort(); }
public Query(string domain, DnsType type, DnsClass dnsClass) { RLog log = new RLog(); log.log("Query.cs", "Setting up query: " + domain, ELogLevel.Info3); if (domain == null) throw new ArgumentNullException("domain"); if (domain.Length == 0 || domain.Length > 255 || !Regex.IsMatch(domain, @"^[a-z|A-Z|0-9|-|_]{1,63}(\.[a-z|A-Z|0-9|-|_]{1,63})+$")) { log.log("Query.cs", "Domain is of incorrect type", ELogLevel.Fatal0); throw new ArgumentException("Domain is of incorrect type"); } if (!Enum.IsDefined(typeof(DnsType), type) || type == DnsType.None) { log.log("Query.cs", "DNS TYPE is out of range", ELogLevel.Fatal0); throw new ArgumentException(); } if (!Enum.IsDefined(typeof(DnsClass), dnsClass) || dnsClass == DnsClass.None) { log.log("Query.cs", "DNS CLASS is out of range", ELogLevel.Fatal0); throw new ArgumentException(); } _domain = domain; _dnsType = type; _dnsClass = dnsClass; }
public static IEnumerable <T> Resolve <T>(string name, DnsType type, DnsClass @class, bool recursionDesired = true) { var req = new Request() { RecursionDesired = recursionDesired }; req.AddQuestion(new Question(name, type, @class)); var bag = new ConcurrentBag <RecordBase>(); Parallel.ForEach(IP4, server => { try { var res = Resolver.Lookup(req, server); if (res.ReturnCode.Equals(ReturnCode.Success)) { Parallel.ForEach(res.Answers, answer => bag.Add(answer.Record)); } } catch (Exception) { //sink it, server might be dead or down } }); return(bag.Cast <T>().Distinct().ToList()); }
/// <summary> /// Construct the question from parameters, checking for safety /// </summary> /// <param name="domain">the domain name to query eg. bigdevelopments.co.uk</param> /// <param name="dnsType">the QTYPE of query eg. DnsType.MX</param> /// <param name="dnsClass">the CLASS of query, invariably DnsClass.IN</param> public Question(string domain, DnsType dnsType, DnsClass dnsClass) { // check the input parameters if (domain == null) { throw new ArgumentNullException("domain"); } // do a sanity check on the domain name to make sure its legal if (domain.Length == 0 || domain.Length > 255 || !Regex.IsMatch(domain, @"^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$")) //There are several issues with thw following Regex: code|project.com, -codeproject.com and code_project.com would be validated //if (domain.Length == 0 || domain.Length > 255 || !Regex.IsMatch(domain, @"^[a-z|A-Z|0-9|-|_]{1,63}(\.[a-z|A-Z|0-9|-|_]{1,63})+$")) { // domain names can't be bigger tan 255 chars, and individal labels can't be bigger than 63 chars throw new ArgumentException(String.Format(Properties.Resources.QuestionExceptionInvalidDomainName, domain), "domain"); } // sanity check the DnsType parameter if (!Enum.IsDefined(typeof(DnsType), dnsType) || dnsType == DnsType.None) { throw new ArgumentOutOfRangeException("dnsType", String.Format(Properties.Resources.QuestionExceptionInvalidDnsType, dnsType)); } // sanity check the DnsClass parameter if (!Enum.IsDefined(typeof(DnsClass), dnsClass) || dnsClass == DnsClass.None) { throw new ArgumentOutOfRangeException("dnsClass", String.Format(Properties.Resources.QuestionExceptionInvalidDnsClass, dnsClass)); } // just remember the values _Domain = domain; _DnsType = dnsType; _DnsClass = dnsClass; }
internal bool EqualsBase(DnsResourceRecord other) { return(other != null && DomainName.Equals(other.DomainName) && DnsType.Equals(other.DnsType) && DnsClass.Equals(other.DnsClass)); }
internal ResourceRecord(SmartPointer pointer) { _domain = pointer.ReadDomain(); _dnsType = (DnsType)pointer.ReadShort(); _dnsClass = (DnsClass)pointer.ReadShort(); _ttl = pointer.ReadInt(); int recordLength = pointer.ReadShort(); switch (_dnsType) { case DnsType.ANAME: _record = new ANameRecord(pointer); break; case DnsType.MX: _record = new MxRecord(pointer); break; case DnsType.NS: _record = new NsRecord(pointer); break; case DnsType.SOA: _record = new NsRecord(pointer); break; case DnsType.CNAME: _record = new CNameRecord(pointer); break; case DnsType.PTR: _record = new CNameRecord(pointer); break; default: pointer += recordLength; break; } }
internal void CopyFrom(DnsResourceRecord rr) { name = rr.name; type = rr.type; klass = rr.klass; ttl = rr.ttl; rdlength = rr.rdlength; m_rdata = rr.m_rdata; }
/// <inheritdoc /> public override IWireSerialiser Read(WireReader reader) { Name = reader.ReadDomainName(); Type = (DnsType)reader.ReadUInt16(); Class = (DnsClass)reader.ReadUInt16(); return(this); }
private bool ContainsInfo(DomainName n, DnsType type, DnsClass cls) { var name = n.ToString(); return(DomainInformation.ContainsKey(name) && DomainInformation[name].Contains(name, type, cls) && !DomainInformation[name].Get(name, type, cls).IsExpired()); }
public DnsQuestionRecord(string name, DnsResourceRecordType type, DnsClass @class) { DnsClient.IsDomainNameValid(name, true); _name = name; _type = type; _class = @class; }
/// <summary> /// Construct the question from parameters, checking for safety /// </summary> /// <param name="domain">the domain name to query eg. bigdevelopments.co.uk</param> /// <param name="dnsType">the QTYPE of query eg. DnsType.MX</param> /// <param name="dnsClass">the CLASS of query, invariably DnsClass.IN</param> public Question(string domain, DnsType dnsType, DnsClass dnsClass) { CheckParams(domain, dnsType, dnsClass); // just remember the values _domain = domain; _dnsType = dnsType; _dnsClass = dnsClass; }
public ResourceRecord Get(DomainName name, DnsType type, DnsClass cls) { lock (DomainRecords) { return(DomainRecords.First(r => r.Name == name && r.Type == type && r.Class == cls)); } }
public DnsResourceRecord(byte[] buffer, ref int index) { Name = DnsUtil.DecodeQuestionName(buffer, ref index); Type = (DnsRecordType)DnsUtil.ToUInt16(buffer, ref index); Class = (DnsClass)DnsUtil.ToUInt16(buffer, ref index); TimeToLive = DnsUtil.ToUInt32(buffer, ref index); DataLength = DnsUtil.ToUInt16(buffer, ref index); Array.Copy(buffer, index, Data, 0, DataLength); index += DataLength; }
public DnsResourceRecord(string name, DnsResourceRecordType type, DnsClass @class, uint ttl, DnsResourceRecordData data) { DnsClient.IsDomainNameValid(name, true); _name = name.ToLower(); _type = type; _class = @class; _ttl = ttl; _data = data; }
public bool Contains(DomainName name, DnsType type, DnsClass cls) { lock (DomainRecords) { return (DomainRecords.First(r => r.Name == name && r.Type == type && r.Class == cls) != null); } }
public DnsResourceRecord(Stream s) { _name = DnsDatagram.DeserializeDomainName(s); _type = (DnsResourceRecordType)DnsDatagram.ReadUInt16NetworkOrder(s); _class = (DnsClass)DnsDatagram.ReadUInt16NetworkOrder(s); _ttl = DnsDatagram.ReadUInt32NetworkOrder(s); switch (_type) { case DnsResourceRecordType.A: _data = new DnsARecord(s); break; case DnsResourceRecordType.NS: _data = new DnsNSRecord(s); break; case DnsResourceRecordType.CNAME: _data = new DnsCNAMERecord(s); break; case DnsResourceRecordType.SOA: _data = new DnsSOARecord(s); break; case DnsResourceRecordType.PTR: _data = new DnsPTRRecord(s); break; case DnsResourceRecordType.MX: _data = new DnsMXRecord(s); break; case DnsResourceRecordType.TXT: _data = new DnsTXTRecord(s); break; case DnsResourceRecordType.AAAA: _data = new DnsAAAARecord(s); break; case DnsResourceRecordType.SRV: _data = new DnsSRVRecord(s); break; case DnsResourceRecordType.CAA: _data = new DnsCAARecord(s); break; default: _data = new DnsUnknownRecord(s); break; } }
public DnsResourceRecord(dynamic jsonResourceRecord) { _name = (jsonResourceRecord.name.Value as string).TrimEnd('.'); _type = (DnsResourceRecordType)jsonResourceRecord.type; _class = DnsClass.IN; _ttl = jsonResourceRecord.TTL; switch (_type) { case DnsResourceRecordType.A: _data = new DnsARecord(jsonResourceRecord); break; case DnsResourceRecordType.NS: _data = new DnsNSRecord(jsonResourceRecord); break; case DnsResourceRecordType.CNAME: _data = new DnsCNAMERecord(jsonResourceRecord); break; case DnsResourceRecordType.SOA: _data = new DnsSOARecord(jsonResourceRecord); break; case DnsResourceRecordType.PTR: _data = new DnsPTRRecord(jsonResourceRecord); break; case DnsResourceRecordType.MX: _data = new DnsMXRecord(jsonResourceRecord); break; case DnsResourceRecordType.TXT: _data = new DnsTXTRecord(jsonResourceRecord); break; case DnsResourceRecordType.AAAA: _data = new DnsAAAARecord(jsonResourceRecord); break; case DnsResourceRecordType.SRV: _data = new DnsSRVRecord(jsonResourceRecord); break; case DnsResourceRecordType.CAA: _data = new DnsCAARecord(jsonResourceRecord); break; default: _data = new DnsUnknownRecord(jsonResourceRecord); break; } }
/// <summary> /// Write a DNS Class. /// </summary> /// <param name="value"> /// The value to write. /// </param> /// <param name="appendSpace"> /// Write a space after the value. /// </param> /// <remarks> /// Either the name of a <see cref="DnsClass"/> or /// the string "CLASSx". /// </remarks> public void WriteDnsClass(DnsClass value, bool appendSpace = true) { if (!Enum.IsDefined(typeof(DnsClass), value)) { text.Write("CLASS"); } text.Write(value); if (appendSpace) { WriteSpace(); } }
void FindAddresses(DomainName name, DnsClass klass, Message response) { var question = new Question { Name = name, Class = klass, Type = DnsType.A }; var _ = FindAnswerAsync(question, response, default(CancellationToken)).Result; question.Type = DnsType.AAAA; _ = FindAnswerAsync(question, response, default(CancellationToken)).Result; }
public DnsResourceRecord(string name, DnsResourceRecordType type, DnsClass @class, uint ttl, DnsResourceRecordData data) { _name = name.ToLower(); _type = type; _class = @class; _ttl = ttl; _data = data; if (_name.Contains("..") || _name.StartsWith(".") || _name.EndsWith(".")) { throw new DnsClientException("Invalid domain name."); } }
public DnsAnswer(NetBinaryReader nbr) { Name = nbr.ReadLblOrPntString(); Type = (QType)nbr.ReadUInt16(); ushort rawClass = nbr.ReadUInt16(); if (rawClass > 65279) rawClass = 0; else if (rawClass > 4 && rawClass < 252) rawClass = 2; else if (rawClass > 255 && rawClass < 65280) rawClass = 2; Class = (DnsClass)rawClass; TTL = nbr.ReadUInt32(); ByteCount = nbr.ReadUInt16(); HandleRData(nbr); }
/// <summary> /// Initializes a new instance of the <see cref="ResourceRecord"/> class by using the specified /// pointer. /// </summary> /// <param name="pointer">The position in the byte array of the record.</param> internal ResourceRecord(RecordPointer pointer) { domain_ = pointer.GetDomain(); dns_type_ = (DnsType)pointer.GetShort(); dns_class_ = (DnsClass)pointer.GetShort(); ttl_ = pointer.GetInt(); // the next short is the record length, we only use it for unrecognised record types. int length = pointer.GetShort(); switch(dns_type_) { case DnsType.MX: record_ = new MXRecord(pointer); break; default: // move the pointer over this unrecognised record pointer += length; break; } }
/// <summary> /// Initializes a new instance_ of the Question class by using the specified domain and dns type and class. /// </summary> /// <param name="domain">The DNS domain of the question.</param> /// <param name="dns_type">The DNS type of the question.</param> /// <param name="dns_class">The DNS class of the question.</param> public Question(string domain, DnsType dns_type, DnsClass dns_class) { if (domain == null) throw new ArgumentNullException("domain"); // sanity check on the domain name to make sure its legal. // domain names can't be bigger than 255 chars, and individual labels can't be bigger // than 63 chars. if(domain.Length == 0 || domain.Length > 255 || !Regex.IsMatch(domain, @"^[a-z|A-Z|0-9|-|_]{1,63}(\.[a-z|A-Z|0-9|-|_]{1,63})+$")) throw new ArgumentException(Resources.MailChecker_InvDomain, "domain"); // sanity check the DnsType. Only support MX. if(dns_type != DnsType.MX) throw new ArgumentOutOfRangeException("dns_type", StringResources.Arg_OutOfRange); // sanity check the DnsClass if((dns_class != DnsClass.IN && dns_class != DnsClass.HS && dns_class != DnsClass.CS && dns_class != DnsClass.CH) || dns_class == DnsClass.NONE) throw new ArgumentOutOfRangeException("dns_class", StringResources.Arg_OutOfRange); domain_ = domain; dns_class_ = dns_class; dns_type_ = dns_type; }
internal DnsResourceRecord(DnsDomainName domainName, DnsType type, DnsClass dnsClass) { DomainName = domainName; DnsType = type; DnsClass = dnsClass; }
internal static bool TryParseBase(DnsDatagram dns, int offsetInDns, out DnsDomainName domainName, out DnsType type, out DnsClass dnsClass, out int numBytesRead) { type = DnsType.Any; dnsClass = DnsClass.Any; if (!DnsDomainName.TryParse(dns, offsetInDns, dns.Length - offsetInDns, out domainName, out numBytesRead)) return false; if (offsetInDns + numBytesRead + MinimumLengthAfterDomainName > dns.Length) return false; type = (DnsType)dns.ReadUShort(offsetInDns + numBytesRead + OffsetAfterDomainName.Type, Endianity.Big); dnsClass = (DnsClass)dns.ReadUShort(offsetInDns + numBytesRead + OffsetAfterDomainName.DnsClass, Endianity.Big); numBytesRead += MinimumLengthAfterDomainName; return true; }
internal Query(SmartPointer pointer) { _domain = pointer.ReadDomain(); _dnsType = (DnsType)pointer.ReadShort(); _dnsClass = (DnsClass)pointer.ReadShort(); }
internal DnsOptResourceRecord(DnsDomainName domainName, DnsClass dnsClass, int ttl, DnsResourceData data) : base(domainName, DnsType.Opt, dnsClass, ttl, data) { }
/// <summary> /// Construct a resource record from a pointer to a byte array /// </summary> /// <param name="pointer">the position in the byte array of the record</param> internal ResourceRecord(Pointer pointer) { // extract the domain, question type, question class and Ttl domain = pointer.ReadDomain(); dnsType = (DnsType)pointer.ReadShort(); dnsClass = (DnsClass)pointer.ReadShort(); ttl = pointer.ReadInt(); // the next short is the record length length = pointer.ReadShort(); // and create the appropriate RDATA record based on the dnsType switch (dnsType) { case DnsType.A: record = new A(pointer); break; case DnsType.AAAA: record = new Aaaa(pointer); break; case DnsType.Cname: record = new Cname(pointer); break; case DnsType.HINFO: record = new HInfo(pointer); break; case DnsType.LOC: record = new Loc(pointer); break; case DnsType.MX: record = new MX(pointer); break; case DnsType.NS: record = new NS(pointer); break; case DnsType.PTR: record = new Ptr(pointer); break; case DnsType.SOA: record = new Soa(pointer); break; case DnsType.SRV: record = new Srv(pointer); break; case DnsType.SSHFP: record = new SshFP(pointer); break; case DnsType.TXT: record = new Txt(pointer, length); break; case DnsType.NULL: record = new Null(pointer, length); break; //mail related RR types case DnsType.MB: record = new MB(pointer); break; case DnsType.MD: record = new MD(pointer); break; case DnsType.MF: record = new MF(pointer); break; case DnsType.MG: record = new MG(pointer); break; case DnsType.MINFO: record = new MInfo(pointer); break; //RFC 1183 RR types case DnsType.AFSDB: record = new Afsdb(pointer); break; case DnsType.RP: record = new Rp(pointer); break; default: { // move the pointer over this unrecognised record pointer += length; break; } } }