Beispiel #1
0
        public void TestUnserializeAResource()
        {
            var stream   = DNSInput(new byte[] { 192, 168, 0, 1 });
            var resource = AResource.Unserialize(stream, 4);

            var expected = new AResource(IPv4Address.Parse("192.168.0.1"));

            Assert.That(resource, Is.EqualTo(expected));
        }
Beispiel #2
0
        public void TestSerializeAResource()
        {
            Tuple <MemoryStream, DNSOutputStream> out_info = DNSOutput();
            var record = new AResource(IPv4Address.Parse("192.168.0.1"));

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

            var expected = new byte[] { 192, 168, 0, 1 };

            Assert.That(record_bytes, Is.EqualTo(expected));
        }
Beispiel #3
0
        public void TestSerializeCompleteAResource()
        {
            Tuple <MemoryStream, DNSOutputStream> out_info = DNSOutput();
            var record = new DNSRecord(
                new Domain("example.com"),
                AddressClass.INTERNET,
                42,
                new AResource(IPv4Address.Parse("192.168.0.1")));

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

            var expected = new byte[]
            {
                7, // Length of example
                101,
                120,
                97,
                109,
                112,
                108,
                101,
                3, // Length of com
                99,
                111,
                109,
                0,
                // A record has code 1
                0,
                1,
                // INTERNET has class 1
                0,
                1,
                // Big-endian representation of 42
                0,
                0,
                0,
                42,
                // Record is 4 bytes long
                0,
                4,
                // The record itself
                192,
                168,
                0,
                1
            };

            Assert.That(record_bytes, Is.EqualTo(expected));
        }
Beispiel #4
0
        public void TestUnserializeDNSPacket()
        {
            var stream = DNSInput(new byte[]
            {
                // Big-endian 42
                0,
                42,
                // This is the query/resonse bit, the query type, the authority
                // bit, the truncation bit, and the recursion desired bit
                4,
                // This is the recursion available bit, the zero segment,
                // and the return code
                128,
                // 1 question
                0,
                1,
                // 1 answer
                0,
                1,
                // 0 authorities
                0,
                0,
                // 0 additional
                0,
                0,
                // The question - A record for example.com
                7,     // Length of example
                101,
                120,
                97,
                109,
                112,
                108,
                101,
                3,                         // Length of com
                99,
                111,
                109,
                0,
                // A record has code 1
                0,
                1,
                // INTERNET has class 1
                0,
                1,
                // The answer - the A record for example.com
                // Pointer to byte 96 - "example.com"
                192,
                12,
                // A record has code 1
                0,
                1,
                // INTERNET has class 1
                0,
                1,
                // Big-endian representation of 42
                0,
                0,
                0,
                42,
                // Record is 4 bytes long
                0,
                4,
                // The record itself
                192,
                168,
                0,
                1
            });
            var packet = DNSPacket.Unserialize(stream);

            var question = new DNSQuestion(
                new Domain("example.com"),
                ResourceRecordType.HOST_ADDRESS,
                AddressClass.INTERNET);

            var answer = new DNSRecord(
                new Domain("example.com"),
                AddressClass.INTERNET,
                42,
                new AResource(IPv4Address.Parse("192.168.0.1")));

            var expected = new DNSPacket(
                42,
                true, QueryType.STANDARD_QUERY, true, false, false, true, ResponseType.NO_ERROR,
                new DNSQuestion[] { question }, new DNSRecord[] { answer }, new DNSRecord[0], new DNSRecord[0]);

            Assert.That(packet, Is.EqualTo(expected));
        }
 public AResource(IPv4Address Address_)
 {
     Address = Address_;
 }
Beispiel #6
0
 /**
  * Writes an IPv4 address to the input stream.
  */
 public void WriteIPv4Address(IPv4Address address)
 {
     WriteBytes(address.GetAddressBytes());
 }