Esempio n. 1
0
        public void TestUnserializeAAAAResource()
        {
            var stream   = DNSInput(new byte[] { 0x20, 0x01, 0x0D, 0xB8, 0xAC, 0x10, 0xFE, 0x01, 0, 0, 0, 0, 0, 0, 0, 0 });
            var resource = AAAAResource.Unserialize(stream, 4);

            var expected = new AAAAResource(IPv6Address.Parse("2001:0DB8:AC10:FE01:0000:0000:0000:0000"));

            Assert.That(resource, Is.EqualTo(expected));
        }
Esempio n. 2
0
        /**
         * Decodes the raw bytes of a DNS resource record into an
         * object.
         */
        public static DNSRecord Unserialize(DNSInputStream stream)
        {
            var name        = stream.ReadDomain();
            var record_type = (ResourceRecordType)stream.ReadUInt16();
            var class_type  = (AddressClass)stream.ReadUInt16();
            var ttl         = stream.ReadUInt32();

            var          record_size = stream.ReadUInt16();
            IDNSResource resource    = null;

            switch (record_type.Normalize())
            {
            case ResourceRecordType.HOST_ADDRESS:
                resource = AResource.Unserialize(stream, record_size);
                break;

            case ResourceRecordType.NAME_SERVER:
                resource = NSResource.Unserialize(stream, record_size);
                break;

            case ResourceRecordType.START_OF_AUTHORITY:
                resource = SOAResource.Unserialize(stream, record_size);
                break;

            case ResourceRecordType.CANONICAL_NAME:
                resource = CNAMEResource.Unserialize(stream, record_size);
                break;

            case ResourceRecordType.MAIL_EXCHANGE:
                resource = MXResource.Unserialize(stream, record_size);
                break;

            case ResourceRecordType.POINTER:
                resource = PTRResource.Unserialize(stream, record_size);
                break;

            case ResourceRecordType.HOST_6ADDRESS:
                resource = AAAAResource.Unserialize(stream, record_size);
                break;

            case ResourceRecordType.UNSUPPORTED:
                // Advance the byte counter - even if we can't parse it,
                // we have to properly ignore it
                stream.ReadBytes(record_size);
                resource = null;
                break;
            }

            return(new DNSRecord(name, class_type.Normalize(), ttl, resource));
        }