Beispiel #1
0
        /// <summary>
        /// Write the answer data into the given byte array and return the number of bytes written
        /// </summary>
        /// <param name="array">Array.</param>
        /// <param name="offset">Offset.</param>
        public int WriteAnswer(byte[] array, int offset)
        {
            int startingOffset = offset;

            // 2 bytes - NAME POINTER
            // 16 bit pointer, with two first bits 11 indiciating we are sending a pointer
            // If the answer is linked to an answer with a pointer, return a pointer, otherwise return a label
            if (this.Question != null && this.Question.DataPointer > 0)
            {
                var pointerBytes = BitConverter.GetBytes(this.Question.DataPointer);
                ByteArray.SwapFields(pointerBytes, 0, 1);

                // First two bits indicate a pointer
                pointerBytes[0] += (1 << 7);
                pointerBytes[0] += (1 << 6);

                array[offset++] = pointerBytes[0];
                array[offset++] = pointerBytes[1];
            }
            // If not linked to an answer, check if we can output the hostname label
            else if (this.Hostname != null && this.Hostname.Length > 0)
            {
                offset += DnsUtil.WriteHostnameLabel(array, offset, this.Hostname);
            }
            // Finally, if we can't find another hostname, we output an empty pointer
            else
            {
                array[offset++] = 0;
                array[offset++] = 0;
            }

            // Write the record and finish
            offset += this.Record.WriteRecord(array, offset);
            return(offset - startingOffset);
        }
        /// <summary>
        /// Write the response data
        /// </summary>
        /// <param name="array"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        protected override int WriteResponseData(byte[] array, int offset)
        {
            int bytesWritten = DnsEncoder.WriteUint16(array, this.Priority, offset);

            bytesWritten += DnsUtil.WriteHostnameLabel(array, offset + bytesWritten, this.Value);

            return(bytesWritten);
        }
        /// <summary>
        /// Write the response data
        /// </summary>
        /// <param name="array"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        protected override int WriteResponseData(byte[] array, int offset)
        {
            int bytesWritten = DnsUtil.WriteHostnameLabel(array, offset, this.MasterHostname);

            bytesWritten += DnsUtil.WriteHostnameLabel(array, offset + bytesWritten, this.ResponsibleMailboxHostname);

            bytesWritten += DnsEncoder.WriteUint32(array, this.SerialNumber, offset + bytesWritten);
            bytesWritten += DnsEncoder.WriteInt32(array, this.RefreshInterval, offset + bytesWritten);
            bytesWritten += DnsEncoder.WriteInt32(array, this.RetryInterval, offset + bytesWritten);
            bytesWritten += DnsEncoder.WriteInt32(array, this.ExpirationLimit, offset + bytesWritten);
            bytesWritten += DnsEncoder.WriteInt32(array, this.MinimumTTL, offset + bytesWritten);

            return(bytesWritten);
        }
        /// <summary>
        /// Write the record response data
        /// </summary>
        /// <param name="array"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        protected override int WriteResponseData(byte[] array, int offset)
        {
            var hostnameLength = DnsUtil.WriteHostnameLabel(array, offset, this.Hostname);

            return(hostnameLength);
        }