/// <summary> /// Constructs an SOA record by reading bytes from a return message /// </summary> /// <param name="pointer">A logical pointer to the bytes holding the record</param> public Soa(Pointer pointer) { // read all fields RFC1035 3.3.13 primaryNameServer = pointer.ReadDomain(); responsibleMailAddress = pointer.ReadDomain(); serial = pointer.ReadInt(); refresh = pointer.ReadInt(); retry = pointer.ReadInt(); expire = pointer.ReadInt(); defaultTtl = pointer.ReadInt(); }
/// <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; } } }
/// <summary> /// Constructs an LOC record by reading bytes from a return message /// </summary> /// <param name="pointer">A logical pointer to the bytes holding the record</param> public Loc(Pointer pointer) { int referenceAlt = 100000 * 100; int latval, longval, altval; version = pointer.ReadByte(); size = pointer.ReadByte(); hPrecision = pointer.ReadByte(); vPrecision = pointer.ReadByte(); latitude = pointer.ReadInt(); longitude = pointer.ReadInt(); altitude = pointer.ReadInt(); latval = latitude - (1 << 31); longval = longitude - (1 << 31); if (altitude < referenceAlt) { //below WGS 84 spheroid altval = referenceAlt - altitude; altsign = -1; } else { altval = altitude - referenceAlt; altsign = 1; } if (latval < 0) { northsouth = 'S'; latval = -latval; } else northsouth = 'N'; //latitude calculation latsecfrag = latval % 1000; latval /= 1000; latsec = latval % 60; latval /= 60; latmin = latval % 60; latval /= 60; latdeg = latval; if (longval < 0) { eastwest = 'W'; longval = -longval; } else eastwest = 'E'; //longitude calculation longsecfrag = longval % 1000; longval /= 1000; longsec = longval % 60; longval /= 60; longmin = longval % 60; longval /= 60; longdeg = longval; //altitude altfrag = altval % 100; altmeters = (altval / 100) * altsign; }