Ejemplo n.º 1
0
        internal static ResourceRecord ReadFrom(PacketReader reader)
        {
            string name = reader.ReadName();
            RecordType type = (RecordType)reader.ReadUShort();
            RecordClass rClass = (RecordClass)reader.ReadUShort();
            DateTime expiry = DateTime.UtcNow + TimeSpan.FromSeconds(reader.ReadInt());

            switch (type)
            {
                case RecordType.Pointer:
                    return new PointerRecord(name, type, rClass, expiry, reader);

                case RecordType.CanonicalName:
                    return new CanonicalNameRecord(name, type, rClass, expiry, reader);

                case RecordType.Address:
                    return new IP4AddressRecord(name, type, rClass, expiry, reader);

                case RecordType.Text:
                    return new TextRecord(name, type, rClass, expiry, reader);

                case RecordType.Service:
                    return new ServiceRecord(name, type, rClass, expiry, reader);

                default:
                    int len = reader.ReadUShort();
                    reader.Position += len;
                    return new ResourceRecord(name, type, rClass, expiry);
            }
        }
Ejemplo n.º 2
0
        internal static ResourceRecord ReadFrom(PacketReader reader)
        {
            string      name   = reader.ReadName();
            RecordType  type   = (RecordType)reader.ReadUShort();
            RecordClass rClass = (RecordClass)reader.ReadUShort();
            DateTime    expiry = DateTime.UtcNow + TimeSpan.FromSeconds(reader.ReadInt());

            switch (type)
            {
            case RecordType.Pointer:
                return(new PointerRecord(name, type, rClass, expiry, reader));

            case RecordType.CanonicalName:
                return(new CanonicalNameRecord(name, type, rClass, expiry, reader));

            case RecordType.Address:
                return(new IP4AddressRecord(name, type, rClass, expiry, reader));

            case RecordType.Text:
                return(new TextRecord(name, type, rClass, expiry, reader));

            case RecordType.Service:
                return(new ServiceRecord(name, type, rClass, expiry, reader));

            default:
                int len = reader.ReadUShort();
                reader.Position += len;
                return(new ResourceRecord(name, type, rClass, expiry));
            }
        }
Ejemplo n.º 3
0
        internal ServiceRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader)
            : base(name, type, rClass, expiry)
        {
            ushort dataLen = reader.ReadUShort();
            int pos = reader.Position;

            _priority = reader.ReadUShort();
            _weight = reader.ReadUShort();
            _port = reader.ReadUShort();
            _target = reader.ReadName();

            reader.Position = pos + dataLen;
        }
        internal ServiceRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader)
            : base(name, type, rClass, expiry)
        {
            ushort dataLen = reader.ReadUShort();
            int    pos     = reader.Position;

            _priority = reader.ReadUShort();
            _weight   = reader.ReadUShort();
            _port     = reader.ReadUShort();
            _target   = reader.ReadName();

            reader.Position = pos + dataLen;
        }
Ejemplo n.º 5
0
        internal PointerRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader)
            : base(name, type, rClass, expiry)
        {
            ushort dataLen = reader.ReadUShort();
            int    pos     = reader.Position;

            _targetName = reader.ReadName();

            reader.Position = pos + dataLen;
        }
Ejemplo n.º 6
0
        internal IP4AddressRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader)
            : base(name, type, rClass, expiry)
        {
            ushort dataLen = reader.ReadUShort();
            int pos = reader.Position;

            _address = new IPAddress(reader.ReadBytes(dataLen));

            reader.Position = pos + dataLen;
        }
Ejemplo n.º 7
0
        internal IP4AddressRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader)
            : base(name, type, rClass, expiry)
        {
            ushort dataLen = reader.ReadUShort();
            int    pos     = reader.Position;

            Address = new IPAddress(reader.ReadBytes(dataLen));

            reader.Position = pos + dataLen;
        }
Ejemplo n.º 8
0
        internal PointerRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader)
            : base(name, type, rClass, expiry)
        {
            ushort dataLen = reader.ReadUShort();
            int pos = reader.Position;

            _targetName = reader.ReadName();

            reader.Position = pos + dataLen;
        }
Ejemplo n.º 9
0
        public static Message Read(PacketReader reader)
        {
            Message result = new Message();

            result.TransactionId = reader.ReadUShort();
            result.Flags         = new MessageFlags(reader.ReadUShort());

            ushort questions         = reader.ReadUShort();
            ushort answers           = reader.ReadUShort();
            ushort authorityRecords  = reader.ReadUShort();
            ushort additionalRecords = reader.ReadUShort();

            for (int i = 0; i < questions; ++i)
            {
                result.Questions.Add(Question.ReadFrom(reader));
            }

            for (int i = 0; i < answers; ++i)
            {
                result.Answers.Add(ResourceRecord.ReadFrom(reader));
            }

            for (int i = 0; i < authorityRecords; ++i)
            {
                result.AuthorityRecords.Add(ResourceRecord.ReadFrom(reader));
            }

            for (int i = 0; i < additionalRecords; ++i)
            {
                result.AdditionalRecords.Add(ResourceRecord.ReadFrom(reader));
            }

            return(result);
        }
Ejemplo n.º 10
0
        public static Message Read(PacketReader reader)
        {
            Message result = new Message();

            result.TransactionId = reader.ReadUShort();
            result.Flags = new MessageFlags(reader.ReadUShort());

            ushort questions = reader.ReadUShort();
            ushort answers = reader.ReadUShort();
            ushort authorityRecords = reader.ReadUShort();
            ushort additionalRecords = reader.ReadUShort();

            for (int i = 0; i < questions; ++i)
            {
                result.Questions.Add(Question.ReadFrom(reader));
            }

            for (int i = 0; i < answers; ++i)
            {
                result.Answers.Add(ResourceRecord.ReadFrom(reader));
            }

            for (int i = 0; i < authorityRecords; ++i)
            {
                result.AuthorityRecords.Add(ResourceRecord.ReadFrom(reader));
            }

            for (int i = 0; i < additionalRecords; ++i)
            {
                result.AdditionalRecords.Add(ResourceRecord.ReadFrom(reader));
            }

            return result;
        }
Ejemplo n.º 11
0
        internal TextRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader)
            : base(name, type, rClass, expiry)
        {
            _values = new Dictionary<string, byte[]>();

            ushort dataLen = reader.ReadUShort();
            int pos = reader.Position;

            while (reader.Position < pos + dataLen)
            {
                int valueLen = reader.ReadByte();
                byte[] valueBinary = reader.ReadBytes(valueLen);

                StoreValue(valueBinary);
            }
        }
Ejemplo n.º 12
0
        internal TextRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader)
            : base(name, type, rClass, expiry)
        {
            _values = new Dictionary <string, byte[]>();

            ushort dataLen = reader.ReadUShort();
            int    pos     = reader.Position;

            while (reader.Position < pos + dataLen)
            {
                int    valueLen    = reader.ReadByte();
                byte[] valueBinary = reader.ReadBytes(valueLen);

                StoreValue(valueBinary);
            }
        }