public static DnsMessage DecodeDnsMessage(byte[] msgData)
        {
            DnsMessage message = new DnsMessage();

            message.ID           = (UInt16)(msgData[0] << 8 | msgData[1]);
            message.Type         = (MessageType)(msgData[2] >> 7);
            message.QueryKind    = (QueryKind)((msgData[2] >> 3) & 15);
            message.ResponseCode = (ResponseCode)(msgData[3] & 15);

            MemoryStream stream = new MemoryStream(msgData);

            stream.Position = 4;
            BinaryReader reader = new BinaryReader(stream);

            int queryCount  = ReadUInt16BE(reader);
            int answerCount = ReadUInt16BE(reader);
            int nsCount     = ReadUInt16BE(reader);
            int arCount     = ReadUInt16BE(reader);

            for (int i = 0; i < queryCount; i++)
            {
                message.Querys.Add(ReadDnsQuery(reader));
            }
            for (int i = 0; i < answerCount; i++)
            {
                message.Answers.Add(ReadResourceRecord(reader));
            }
            for (int i = 0; i < nsCount; i++)
            {
                message.AuthorityRecords.Add(ReadResourceRecord(reader));
            }
            for (int i = 0; i < arCount; i++)
            {
                message.AdditionalRecords.Add(ReadResourceRecord(reader));
            }

            return(message);
        }