コード例 #1
0
ファイル: SOARecord.cs プロジェクト: schmitch/net-dns
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     PrimaryName  = reader.ReadDomainName();
     Mailbox      = reader.ReadDomainName();
     SerialNumber = reader.ReadUInt32();
     Refresh      = reader.ReadTimeSpan32();
     Retry        = reader.ReadTimeSpan32();
     Expire       = reader.ReadTimeSpan32();
     Minimum      = reader.ReadTimeSpan32();
 }
コード例 #2
0
        public void Reading()
        {
            var bytes = new byte[]
            {
                0x01, (byte)'a', 0,
                0x01, (byte)'b', 0,
                0XC0, 3
            };
            var ms     = new MemoryStream(bytes);
            var reader = new WireReader(ms);

            Assert.AreEqual("a", reader.ReadDomainName());
            Assert.AreEqual("b", reader.ReadDomainName());
            Assert.AreEqual("b", reader.ReadDomainName());
        }
コード例 #3
0
ファイル: ResourceRecord.cs プロジェクト: schmitch/net-dns
        /// <inheritdoc />
        public override IWireSerialiser Read(WireReader reader)
        {
            // Read standard properties of a resource record.
            Name  = reader.ReadDomainName();
            Type  = (DnsType)reader.ReadUInt16();
            Class = (DnsClass)reader.ReadUInt16();
            TTL   = reader.ReadTimeSpan32();
            int length = reader.ReadUInt16();

            // Find a specific class for the TYPE or default
            // to UnknownRecord.
            var specific = ResourceRegistry.Create(Type);

            specific.Name  = Name;
            specific.Type  = Type;
            specific.Class = Class;
            specific.TTL   = TTL;

            // Read the specific properties of the resource record.
            var end = reader.Position + length;

            specific.ReadData(reader, length);
            if (reader.Position != end)
            {
                throw new InvalidDataException("Found extra data while decoding RDATA.");
            }

            return(specific);
        }
コード例 #4
0
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     Priority = reader.ReadUInt16();
     Weight   = reader.ReadUInt16();
     Port     = reader.ReadUInt16();
     Target   = reader.ReadDomainName();
 }
コード例 #5
0
        public void BufferOverflow_DomainName()
        {
            var ms     = new MemoryStream(new byte[] { 1, (byte)'a' });
            var reader = new WireReader(ms);

            ExceptionAssert.Throws <EndOfStreamException>(() => reader.ReadDomainName());
        }
コード例 #6
0
        /// <inheritdoc />
        public override IWireSerialiser Read(WireReader reader)
        {
            Name  = reader.ReadDomainName();
            Type  = (DnsType)reader.ReadUInt16();
            Class = (DnsClass)reader.ReadUInt16();

            return(this);
        }
コード例 #7
0
        public void CanonicalDomainName()
        {
            var ms     = new MemoryStream();
            var writer = new WireWriter(ms)
            {
                CanonicalForm = true
            };

            writer.WriteDomainName("FOO");
            writer.WriteDomainName("FOO");
            Assert.AreEqual(5 * 2, writer.Position);

            ms.Position = 0;
            var reader = new WireReader(ms);

            Assert.AreEqual("foo", reader.ReadDomainName());
            Assert.AreEqual("foo", reader.ReadDomainName());
        }
コード例 #8
0
        public void Writing_Past_MaxPointer()
        {
            var ms     = new MemoryStream();
            var writer = new WireWriter(ms);

            writer.WriteBytes(new byte[0x4000]);
            writer.WriteDomainName("a");
            writer.WriteDomainName("b");
            writer.WriteDomainName("b");

            ms.Position = 0;
            var reader = new WireReader(ms);

            reader.ReadBytes(0x4000);
            Assert.AreEqual("a", reader.ReadDomainName());
            Assert.AreEqual("b", reader.ReadDomainName());
            Assert.AreEqual("b", reader.ReadDomainName());
        }
コード例 #9
0
        public void LengthPrefixedScope()
        {
            var ms     = new MemoryStream();
            var writer = new WireWriter(ms);

            writer.WriteString("abc");
            writer.PushLengthPrefixedScope();
            writer.WriteDomainName("a");
            writer.WriteDomainName("a");
            writer.PopLengthPrefixedScope();

            ms.Position = 0;
            var reader = new WireReader(ms);

            Assert.AreEqual("abc", reader.ReadString());
            Assert.AreEqual(5, reader.ReadUInt16());
            Assert.AreEqual("a", reader.ReadDomainName());
            Assert.AreEqual("a", reader.ReadDomainName());
        }
コード例 #10
0
ファイル: TKEYRecord.cs プロジェクト: schmitch/net-dns
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     Algorithm  = reader.ReadDomainName();
     Inception  = reader.ReadDateTime32();
     Expiration = reader.ReadDateTime32();
     Mode       = (KeyExchangeMode)reader.ReadUInt16();
     Error      = (MessageStatus)reader.ReadUInt16();
     Key        = reader.ReadUInt16LengthPrefixedBytes();
     OtherData  = reader.ReadUInt16LengthPrefixedBytes();
 }
コード例 #11
0
        /// <inheritdoc />
        public override void ReadData(WireReader reader, int length)
        {
            var end = reader.Position + length;

            NextOwnerName = reader.ReadDomainName();
            while (reader.Position < end)
            {
                Types.AddRange(reader.ReadBitmap().Select(t => (DnsType)t));
            }
        }
コード例 #12
0
        public void Reading_Labels()
        {
            var bytes = new byte[]
            {
                0x01, (byte)'a', 0x01, (byte)'b', 0x01, (byte)'c', 00,
                0xC0, 0x00,
                0xC0, 0x02,
                0xC0, 0x04,
                0x01, (byte)'x', 0xC0, 0x02,
            };
            var ms     = new MemoryStream(bytes);
            var reader = new WireReader(ms);

            Assert.AreEqual("a.b.c", reader.ReadDomainName());
            Assert.AreEqual("a.b.c", reader.ReadDomainName());
            Assert.AreEqual("b.c", reader.ReadDomainName());
            Assert.AreEqual("c", reader.ReadDomainName());
            Assert.AreEqual("x.b.c", reader.ReadDomainName());
        }
コード例 #13
0
ファイル: TSIGRecord.cs プロジェクト: schmitch/net-dns
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     Algorithm         = reader.ReadDomainName();
     TimeSigned        = reader.ReadDateTime48();
     Fudge             = reader.ReadTimeSpan16();
     MAC               = reader.ReadUInt16LengthPrefixedBytes();
     OriginalMessageId = reader.ReadUInt16();
     Error             = (MessageStatus)reader.ReadUInt16();
     OtherData         = reader.ReadUInt16LengthPrefixedBytes();
 }
コード例 #14
0
        public void NullDomainName_Class()
        {
            var ms     = new MemoryStream();
            var writer = new WireWriter(ms);

            writer.WriteDomainName((DomainName)null);
            writer.WriteString("abc");

            ms.Position = 0;
            var reader = new WireReader(ms);

            Assert.AreEqual("", reader.ReadDomainName());
            Assert.AreEqual("abc", reader.ReadString());
        }
コード例 #15
0
        public void Read_EscapedDotDomainName()
        {
            var domainName = @"a\.b";
            var ms         = new MemoryStream();
            var writer     = new WireWriter(ms);

            writer.WriteDomainName(domainName);

            ms.Position = 0;
            var reader = new WireReader(ms);
            var name   = reader.ReadDomainName();

            Assert.AreEqual(domainName, name);
        }
コード例 #16
0
ファイル: RRSIGRecord.cs プロジェクト: schmitch/net-dns
        /// <inheritdoc />
        public override void ReadData(WireReader reader, int length)
        {
            var end = reader.Position + length;

            TypeCovered         = (DnsType)reader.ReadUInt16();
            Algorithm           = (SecurityAlgorithm)reader.ReadByte();
            Labels              = reader.ReadByte();
            OriginalTTL         = reader.ReadTimeSpan32();
            SignatureExpiration = reader.ReadDateTime32();
            SignatureInception  = reader.ReadDateTime32();
            KeyTag              = reader.ReadUInt16();
            SignerName          = reader.ReadDomainName();
            Signature           = reader.ReadBytes(end - reader.Position);
        }
コード例 #17
0
        public void Roundtrip()
        {
            var someBytes = new byte[] { 1, 2, 3 };
            var someDate  = new DateTime(1997, 1, 21, 3, 4, 5, DateTimeKind.Utc);

            var ms     = new MemoryStream();
            var writer = new WireWriter(ms);

            writer.WriteDomainName("emanon.org");
            writer.WriteString("alpha");
            writer.WriteTimeSpan32(TimeSpan.FromHours(3));
            writer.WriteUInt16(ushort.MaxValue);
            writer.WriteUInt32(uint.MaxValue);
            writer.WriteUInt48(0XFFFFFFFFFFFFul);
            writer.WriteBytes(someBytes);
            writer.WriteByteLengthPrefixedBytes(someBytes);
            writer.WriteByteLengthPrefixedBytes(null);
            writer.WriteIPAddress(IPAddress.Parse("127.0.0.1"));
            writer.WriteIPAddress(IPAddress.Parse("2406:e001:13c7:1:7173:ef8:852f:25cb"));
            writer.WriteDateTime32(someDate);
            writer.WriteDateTime48(someDate);

            ms.Position = 0;
            var reader = new WireReader(ms);

            Assert.AreEqual("emanon.org", reader.ReadDomainName());
            Assert.AreEqual("alpha", reader.ReadString());
            Assert.AreEqual(TimeSpan.FromHours(3), reader.ReadTimeSpan32());
            Assert.AreEqual(ushort.MaxValue, reader.ReadUInt16());
            Assert.AreEqual(uint.MaxValue, reader.ReadUInt32());
            Assert.AreEqual(0XFFFFFFFFFFFFul, reader.ReadUInt48());
            CollectionAssert.AreEqual(someBytes, reader.ReadBytes(3));
            CollectionAssert.AreEqual(someBytes, reader.ReadByteLengthPrefixedBytes());
            CollectionAssert.AreEqual(new byte[0], reader.ReadByteLengthPrefixedBytes());
            Assert.AreEqual(IPAddress.Parse("127.0.0.1"), reader.ReadIPAddress());
            Assert.AreEqual(IPAddress.Parse("2406:e001:13c7:1:7173:ef8:852f:25cb"), reader.ReadIPAddress(16));
            Assert.AreEqual(someDate, reader.ReadDateTime32());
            Assert.AreEqual(someDate, reader.ReadDateTime48());
        }
コード例 #18
0
ファイル: RPRecord.cs プロジェクト: schmitch/net-dns
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     Mailbox  = reader.ReadDomainName();
     TextName = reader.ReadDomainName();
 }
コード例 #19
0
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     Authority = reader.ReadDomainName();
 }
コード例 #20
0
ファイル: DNAMERecord.cs プロジェクト: schmitch/net-dns
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     Target = reader.ReadDomainName();
 }
コード例 #21
0
ファイル: MXRecord.cs プロジェクト: schmitch/net-dns
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     Preference = reader.ReadUInt16();
     Exchange   = reader.ReadDomainName();
 }
コード例 #22
0
ファイル: AFSDBRecord.cs プロジェクト: schmitch/net-dns
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     Subtype = reader.ReadUInt16();
     Target  = reader.ReadDomainName();
 }