Example #1
0
        /// <summary>
        /// Formats and writes this header to the specified query writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="writer"/> is <see langword="null"/>.
        /// </exception>
        public virtual void Write(IDnsWriter writer)
        {
            Guard.NotNull(writer, "writer");

            writer.WriteUInt16((ushort)this.Id);

            byte b3 = 0;

            if (!this.IsQuery)
            {
                b3 |= 0x80;
            }
            b3 |= (byte)(((byte)this.OpCode & 0x0F) << 3);
            if (this.IsAuthorative)
            {
                b3 |= 0x04;
            }
            if (this.IsTruncated)
            {
                b3 |= 0x02;
            }
            if (this.IsRecursionDesired)
            {
                b3 |= 0x01;
            }
            writer.WriteByte(b3);

            byte b4 = (byte)this.ResponseCode;

            if (this.IsRecursionAllowed)
            {
                b4 |= 0x80;
            }
            writer.WriteByte(b4);

            writer.WriteUInt16(this.QuestionCount);
            writer.WriteUInt16(this.AnswerCount);
            writer.WriteUInt16(this.AuthorityCount);
            writer.WriteUInt16(this.AdditionalCount);
        }
Example #2
0
        /// <summary>
        /// Writes the RDATA of this resource record to the specified
        /// <see cref="AK.Net.Dns.IDnsWriter"/>.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="writer"/> is <see langword="null"/>.
        /// </exception>
        public override void WriteData(IDnsWriter writer)
        {
            Guard.NotNull(writer, "writer");

            const int BITS_IN_BYTE = 8;

            byte[] buf;

            writer.WriteIPAddress(this.Address);
            writer.WriteByte(this.Protocol);
            if (this.Bitmap.Count % BITS_IN_BYTE != 0)
            {
                this.Bitmap.Length = this.Bitmap.Count + (this.Bitmap.Count % BITS_IN_BYTE);
            }
            buf = new byte[this.Bitmap.Length / BITS_IN_BYTE];
            this.Bitmap.CopyTo(buf, 0);
            writer.WriteBytes(buf);
        }