Ejemplo n.º 1
0
        /// <summary>
        /// reads an entire string of format xx.yy.zz
        /// </summary>
        /// <returns></returns>
        public string ReadDomain()
        {
            StringBuilder domain = new StringBuilder();
            int           len    = 0;

            while ((len = ReadByte()) != 0)
            {
                if ((len & 0xc0) == 0xc0)
                {
                    SmartPointer newPointer = Copy();
                    newPointer.SetPosition((len & 0x3f) << 8 | ReadByte());

                    domain.Append(newPointer.ReadDomain());
                    return(domain.ToString());
                }

                while (len > 0)
                {
                    domain.Append(ReadChar());
                    len--;
                }

                if (Peek() != 0)
                {
                    domain.Append('.');
                }
            }

            return(domain.ToString());
        }
Ejemplo n.º 2
0
        internal WKSRecord(SmartPointer pointer)
        {
            _address = pointer.ReadIPAddress();
            _protocol = pointer.ReadByte();

            throw new NotImplementedException("Haven't finished this yet");
        }
Ejemplo n.º 3
0
        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;
            }
        }
Ejemplo n.º 4
0
        internal WKSRecord(SmartPointer pointer)
        {
            _address  = pointer.ReadIPAddress();
            _protocol = pointer.ReadByte();

            throw new NotImplementedException("Haven't finished this yet");
        }
Ejemplo n.º 5
0
        internal Response(byte[] message)
        {
            byte flags1 = message[2];
            byte flags2 = message[3];

            int returnCode = flags2 & 15;

            if (returnCode > 6)
            {
                returnCode = 6;
            }
            _returnCode = (ReturnCode)returnCode;

            _authoritativeAnswer = ((flags1 & 4) != 0);
            _recursionAvailable  = ((flags2 & 128) != 0);
            _truncated           = ((flags1 & 2) != 0);

            int _questionsCount = GetShort(message, 4);

            _questions = new List <Query>();
            int _answersCount = GetShort(message, 6);

            _answers = new List <Answer>();
            int _nameServersCount = GetShort(message, 8);

            _nameServers = new List <NameServer>();
            int _additionalRecordsCount = GetShort(message, 10);

            _additionalRecords = new List <AdditionalRecord>();

            SmartPointer pointer = new SmartPointer(message, 12);

            for (int i = 0; i < _questionsCount; i++)
            {
                try
                {
                    _questions.Add(new Query(pointer));
                }
                catch
                {
                    throw new Exception("Invalid Response");
                }
            }

            for (int i = 0; i < _answersCount; i++)
            {
                _answers.Add(new Answer(pointer));
            }

            for (int i = 0; i < _nameServersCount; i++)
            {
                _nameServers.Add(new NameServer(pointer));
            }

            for (int i = 0; i < _additionalRecordsCount; i++)
            {
                _additionalRecords.Add(new AdditionalRecord(pointer));
            }
        }
Ejemplo n.º 6
0
 internal SoaRecord(SmartPointer pointer)
 {
     _primaryNameServer      = pointer.ReadDomain();
     _responsibleMailAddress = pointer.ReadDomain();
     _serial     = pointer.ReadInt();
     _refresh    = pointer.ReadInt();
     _retry      = pointer.ReadInt();
     _expire     = pointer.ReadInt();
     _defaultTTL = pointer.ReadInt();
 }
Ejemplo n.º 7
0
 internal SoaRecord(SmartPointer pointer)
 {
     _primaryNameServer = pointer.ReadDomain();
     _responsibleMailAddress = pointer.ReadDomain();
     _serial = pointer.ReadInt();
     _refresh = pointer.ReadInt();
     _retry = pointer.ReadInt();
     _expire = pointer.ReadInt();
     _defaultTTL = pointer.ReadInt();
 }
Ejemplo n.º 8
0
        internal ANameRecord(SmartPointer pointer)
        {
            /*byte b1 = pointer.ReadByte();
             * byte b2 = pointer.ReadByte();
             * byte b3 = pointer.ReadByte();
             * byte b4 = pointer.ReadByte();
             *
             * _ipAddress = IPAddress.Parse(string.Format("{0}.{1}.{2}.{3}", b1, b2, b3, b4));*/

            _ipAddress = pointer.ReadIPAddress();
        }
Ejemplo n.º 9
0
        internal ANameRecord(SmartPointer pointer)
        {
            /*byte b1 = pointer.ReadByte();
            byte b2 = pointer.ReadByte();
            byte b3 = pointer.ReadByte();
            byte b4 = pointer.ReadByte();

            _ipAddress = IPAddress.Parse(string.Format("{0}.{1}.{2}.{3}", b1, b2, b3, b4));*/

            _ipAddress = pointer.ReadIPAddress();
        }
Ejemplo n.º 10
0
        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;
            }
        }
Ejemplo n.º 11
0
 internal Query(SmartPointer pointer)
 {
     _domain = pointer.ReadDomain();
     _dnsType = (DnsType)pointer.ReadShort();
     _dnsClass = (DnsClass)pointer.ReadShort();
 }
Ejemplo n.º 12
0
 internal MxRecord(SmartPointer pointer)
 {
     _preference = pointer.ReadShort();
     _domainName = pointer.ReadDomain();
 }
Ejemplo n.º 13
0
 internal CNameRecord(SmartPointer pointer)
 {
     _domain = pointer.ReadDomain();
 }
Ejemplo n.º 14
0
        internal Response(byte[] message)
        {
            byte flags1 = message[2];
            byte flags2 = message[3];

            int returnCode = flags2 & 15;

            if (returnCode > 6) returnCode = 6;
            _returnCode = (ReturnCode)returnCode;

            _authoritativeAnswer = ((flags1 & 4) != 0);
            _recursionAvailable = ((flags2 & 128) != 0);
            _truncated = ((flags1 & 2) != 0);

            int _questionsCount = GetShort(message, 4);
            _questions = new List<Query>();
            int _answersCount = GetShort(message, 6);
            _answers = new List<Answer>();
            int _nameServersCount = GetShort(message, 8);
            _nameServers = new List<NameServer>();
            int _additionalRecordsCount = GetShort(message, 10);
            _additionalRecords = new List<AdditionalRecord>();

            SmartPointer pointer = new SmartPointer(message, 12);

            for (int i = 0; i < _questionsCount; i++)
            {
                try
                {
                    _questions.Add(new Query(pointer));
                }
                catch
                {
                    throw new Exception("Invalid Response");
                }
            }

            for (int i = 0; i < _answersCount; i++)
            {
                _answers.Add(new Answer(pointer));
            }

            for (int i = 0; i < _nameServersCount; i++)
            {
                _nameServers.Add(new NameServer(pointer));
            }

            for (int i = 0; i < _additionalRecordsCount; i++)
            {
                _additionalRecords.Add(new AdditionalRecord(pointer));
            }
        }
Ejemplo n.º 15
0
 internal Answer(SmartPointer pointer) : base(pointer)
 {
 }
Ejemplo n.º 16
0
 internal AdditionalRecord(SmartPointer pointer) : base(pointer) { }
Ejemplo n.º 17
0
 internal CNameRecord(SmartPointer pointer)
 {
     _domain = pointer.ReadDomain();
 }
Ejemplo n.º 18
0
 internal Query(SmartPointer pointer)
 {
     _domain   = pointer.ReadDomain();
     _dnsType  = (DnsType)pointer.ReadShort();
     _dnsClass = (DnsClass)pointer.ReadShort();
 }
Ejemplo n.º 19
0
 internal RouteThroughRecord(SmartPointer pointer)
 {
     _preference = pointer.ReadShort();
     _intermediateHost = pointer.ReadDomain();
 }
Ejemplo n.º 20
0
 internal NsRecord(SmartPointer pointer)
 {
     _domainName = pointer.ReadDomain();
 }
Ejemplo n.º 21
0
 internal AdditionalRecord(SmartPointer pointer) : base(pointer)
 {
 }
Ejemplo n.º 22
0
 internal Answer(SmartPointer pointer) : base(pointer) { }
Ejemplo n.º 23
0
 internal NsRecord(SmartPointer pointer)
 {
     _domainName = pointer.ReadDomain();
 }
Ejemplo n.º 24
0
 internal NameServer(SmartPointer pointer) : base(pointer)
 {
 }
Ejemplo n.º 25
0
 internal NameServer(SmartPointer pointer) : base(pointer) { }
Ejemplo n.º 26
0
 internal RouteThroughRecord(SmartPointer pointer)
 {
     _preference       = pointer.ReadShort();
     _intermediateHost = pointer.ReadDomain();
 }
Ejemplo n.º 27
0
 internal MxRecord(SmartPointer pointer)
 {
     _preference = pointer.ReadShort();
     _domainName = pointer.ReadDomain();
 }