public static DnsQuery ReadDnsQuery(BinaryReader reader)
        {
            String     domainName = ReadDomainName(reader);
            QueryType  qtype      = (QueryType)ReadUInt16BE(reader);
            QueryClass qclass     = (QueryClass)ReadUInt16BE(reader);

            DnsQuery query = new DnsQuery(domainName, qtype, qclass);

            return(query);
        }
        public static byte[] EncodeDnsQuery(DnsQuery query)
        {
            MemoryStream stream = new MemoryStream(256);
            BinaryWriter writer = new BinaryWriter(stream);

            //QNAME
            string[] labels = query.DomainName.Split('.');
            foreach (string label in labels)
            {
                writer.Write((byte)label.Length);
                writer.Write(Encoding.ASCII.GetBytes(label));
            }
            writer.Write((byte)0);

            //QTYPE
            WriteUInt16BE(writer, (UInt16)query.QueryType);

            //QCLASS
            WriteUInt16BE(writer, (UInt16)query.QueryClass);

            return(stream.ToArray());
        }