Exemple #1
0
 /// <summary>
 /// Constructs an MX record by reading bytes from a return message
 /// </summary>
 /// <param name="pointer">A logical pointer to the bytes holding the record</param>
 public Srv(Pointer pointer)
 {
     this.priority = pointer.ReadShort();
     this.weight = pointer.ReadShort();
     this.port = pointer.ReadShort();
     this.hostname = pointer.ReadDomain();
 }
Exemple #2
0
 /// <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();
 }
Exemple #3
0
        /// <summary>
        /// Construct a Response object from the supplied byte array
        /// </summary>
        /// <param name="message">a byte array returned from a DNS server query</param>
        internal Response(byte[] message)
        {
            // the bit flags are in bytes 2 and 3
            byte flags1 = message[2];
            byte flags2 = message[3];

            // get return code from lowest 4 bits of byte 3
            int returnCode_ = flags2 & 15;

            // if its in the reserved section, set to other
            if (returnCode_ > 6) returnCode_ = 6;
            returnCode = (ReturnCode)returnCode_;

            // other bit flags
            authoritativeAnswer = ((flags1 & 4) != 0);
            recursionAvailable = ((flags2 & 128) != 0);
            truncated = ((flags1 & 2) != 0);

            // create the arrays of response objects
            questions = new Question[GetShort(message, 4)];
            answers = new Answer[GetShort(message, 6)];
            nameServers = new NameServer[GetShort(message, 8)];
            additionalRecords = new AdditionalRecord[GetShort(message, 10)];

            // need a pointer to do this, position just after the header
            Pointer pointer = new Pointer(message, 12);

            // and now populate them, they always follow this order
            for (int index = 0; index < questions.Length; index++)
            {
                try
                {
                    // try to build a quesion from the response
                    questions[index] = new Question(pointer);
                }
                catch (Exception ex)
                {
                    // something grim has happened, we can't continue
                    throw new InvalidResponseException(ex);
                }
            }
            for (int index = 0; index < answers.Length; index++)
            {
                answers[index] = new Answer(pointer);
            }
            for (int index = 0; index < nameServers.Length; index++)
            {
                nameServers[index] = new NameServer(pointer);
            }
            for (int index = 0; index < additionalRecords.Length; index++)
            {
                additionalRecords[index] = new AdditionalRecord(pointer);
            }
        }
Exemple #4
0
        /// <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;
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Constructs a NS record by reading bytes from a return message
        /// </summary>
        /// <param name="pointer">A logical pointer to the bytes holding the record</param>
        public SshFP(Pointer pointer)
        {
            //detect algorithm
            byte a = pointer.ReadByte();
            switch(a)
            {
                case 0: this.algorithm = "Reserved"; break;
                case 1: this.algorithm = "RSA"; break;
                case 2: this.algorithm = "DSS"; break;
                default: this.algorithm = "Unknown"; break;
            }

            //detect fingerprint type
            byte fpt = pointer.ReadByte();
            switch(fpt)
            {
                case 0: this.fingerPrintType = "Reserved"; break;
                case 1: this.fingerPrintType = "RSA-1"; break;
                default: this.fingerPrintType = "Unknown"; break;
            }

            this.fingerPrint = pointer.ReadString();	//read the fingerprint (hex format)
        }
Exemple #6
0
 internal NameServer(Pointer pointer)
     : base(pointer)
 {
 }
Exemple #7
0
 internal Answer(Pointer pointer)
     : base(pointer)
 {
 }
Exemple #8
0
 internal AdditionalRecord(Pointer pointer)
     : base(pointer)
 {
 }
Exemple #9
0
 /// <summary>
 /// Constructs an MX record by reading bytes from a return message
 /// </summary>
 /// <param name="pointer">A logical pointer to the bytes holding the record</param>
 public MX(Pointer pointer)
 {
     preference = pointer.ReadShort();
     hostname = pointer.ReadDomain();
 }
Exemple #10
0
 /// <summary>
 /// Constructs a NS record by reading bytes from a return message
 /// </summary>
 /// <param name="pointer">A logical pointer to the bytes holding the record</param>
 public MInfo(Pointer pointer)
 {
     this.ownerMailbox = pointer.ReadString();
     this.errorMailbox = pointer.ReadString();
 }
Exemple #11
0
 /// <summary>
 /// Constructs an AAAA record by reading bytes from a return message
 /// </summary>
 /// <param name="pointer">A logical pointer to the bytes holding the record</param>
 public Aaaa(Pointer pointer)
 {
     byte[] b = pointer.ReadBytes(16);
     ipAddress = new IPAddress(b);
 }
Exemple #12
0
 /// <summary>
 /// Constructs a NS record by reading bytes from a return message
 /// </summary>
 /// <param name="pointer">A logical pointer to the bytes holding the record</param>
 internal Afsdb(Pointer pointer)
 {
     pref = pointer.ReadShort();
     hostname = pointer.ReadDomain();
 }
Exemple #13
0
 /// <summary>
 /// Constructs a NS record by reading bytes from a return message
 /// </summary>
 /// <param name="pointer">A logical pointer to the bytes holding the record</param>
 public Null(Pointer pointer, int length)
 {
     data = pointer.ReadBytes(length);
 }
Exemple #14
0
 /// <summary>
 /// Constructs a HINFO record by reading bytes from a return message
 /// </summary>
 /// <param name="pointer">A logical pointer to the bytes holding the record</param>
 public HInfo(Pointer pointer)
 {
     this.cpu = pointer.ReadString();
     this.os = pointer.ReadString();
 }
Exemple #15
0
 /// <summary>
 /// Constructs a NS record by reading bytes from a return message
 /// </summary>
 /// <param name="pointer">A logical pointer to the bytes holding the record</param>
 public Txt(Pointer pointer, int length)
 {
     pointer.ReadByte();	//ignore first (NULL) byte
     text = pointer.ReadString(length - 1);
 }
Exemple #16
0
 /// <summary>
 /// Constructs an ANAME record by reading bytes from a return message
 /// </summary>
 /// <param name="pointer">A logical pointer to the bytes holding the record</param>
 public A(Pointer pointer)
 {
     byte[] bytes = pointer.ReadBytes(4);
     ipAddress = new IPAddress(bytes);
 }
Exemple #17
0
 /// <summary>
 /// Constructs a NS record by reading bytes from a return message
 /// </summary>
 /// <param name="pointer">A logical pointer to the bytes holding the record</param>
 public Ptr(Pointer pointer)
 {
     hostname = pointer.ReadDomain();
 }
Exemple #18
0
 /// <summary>
 /// Constructs a NS record by reading bytes from a return message
 /// </summary>
 /// <param name="pointer">A logical pointer to the bytes holding the record</param>
 public MD(Pointer pointer)
 {
     madname = pointer.ReadDomain();
 }
Exemple #19
0
        /// <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;
        }
Exemple #20
0
 /// <summary>
 /// Constructs a NS record by reading bytes from a return message
 /// </summary>
 /// <param name="pointer">A logical pointer to the bytes holding the record</param>
 internal Rp(Pointer pointer)
 {
     this.mailboxHostname = pointer.ReadDomain();
     this.textHostname = pointer.ReadDomain();
 }