Пример #1
0
        public void TestUnserializeSOAResource()
        {
            var stream = DNSInput(new byte[]
            {
                3, 100, 110, 115,
                7, 101, 120, 97, 109, 112, 108, 101,
                3, 99, 111, 109,
                0,
                10, 104, 111, 115, 116, 109, 97, 115, 116, 101, 114,
                192, 4,
                0, 0, 0, 42,
                0, 9, 58, 128,
                0, 0, 14, 16,
                0, 9, 58, 128,
                0, 1, 81, 128
            });
            var resource = SOAResource.Unserialize(stream, 4);

            UInt32 one_hour = 60 * 60;
            UInt32 one_day  = one_hour * 24;
            UInt32 one_week = one_day * 7;

            var expected = new SOAResource(
                new Domain("dns.example.com"),
                new Domain("hostmaster.example.com"),
                42,
                one_week,
                one_hour,
                one_week,
                one_day);

            Assert.That(resource, Is.EqualTo(expected));
        }
Пример #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));
        }
Пример #3
0
        public void TestSerializeSOAResource()
        {
            UInt32 one_hour = 60 * 60;
            UInt32 one_day  = one_hour * 24;
            UInt32 one_week = one_day * 7;

            Tuple <MemoryStream, DNSOutputStream> out_info = DNSOutput();
            var record = new SOAResource(
                new Domain("dns.example.com"),
                new Domain("hostmaster.example.com"),
                42,
                one_week,
                one_hour,
                one_week,
                one_day);

            record.Serialize(out_info.Item2);
            var record_bytes = out_info.Item1.ToArray();

            var expected = new byte[]
            {
                3, // Length of dns
                100,
                110,
                115,
                7, // Length of example
                101,
                120,
                97,
                109,
                112,
                108,
                101,
                3, // Length of com
                99,
                111,
                109,
                0,
                10, // Length of hostmaster
                104,
                111,
                115,
                116,
                109,
                97,
                115,
                116,
                101,
                114,
                // Reference to byte 4, 'example.com'
                192,
                4,
                // Big-endian 42
                0,
                0,
                0,
                42,
                // Big-endian 604,800
                0,
                9,
                58,
                128,
                // Big-endian 3,600
                0,
                0,
                14,
                16,
                // Big-endian 604,800
                0,
                9,
                58,
                128,
                // Big-endian 86,400
                0,
                1,
                81,
                128
            };

            Assert.That(record_bytes, Is.EqualTo(expected));
        }