示例#1
0
        /// <summary>
        /// Parses resource record from reply data.
        /// </summary>
        /// <param name="name">DNS domain name that owns a resource record.</param>
        /// <param name="reply">DNS server reply data.</param>
        /// <param name="offset">Current offset in reply data.</param>
        /// <param name="rdLength">Resource record data length.</param>
        /// <param name="ttl">Time to live in seconds.</param>
        public static DnsRecord_HINFO Parse(string name, byte[] reply, ref int offset, int rdLength, int ttl)
        {
            /* RFC 1035 3.3.2. HINFO RDATA format
             *
             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
             *          /                      CPU                      /
             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
             *          /                       OS                      /
             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
             *
             *          CPU     A <character-string> which specifies the CPU type.
             *
             *          OS      A <character-string> which specifies the operating
             *                          system type.
             *
             *                          Standard values for CPU and OS can be found in [RFC-1010].
             *
             */

            // CPU
            string cpu = DnsTool.ReadCharacterString(reply, ref offset);

            // OS
            string os = DnsTool.ReadCharacterString(reply, ref offset);

            return(new DnsRecord_HINFO(name, cpu, os, ttl));
        }
示例#2
0
        /// <summary>
        /// Parses resource record from reply data.
        /// </summary>
        /// <param name="name">DNS domain name that owns a resource record.</param>
        /// <param name="reply">DNS server reply data.</param>
        /// <param name="offset">Current offset in reply data.</param>
        /// <param name="rdLength">Resource record data length.</param>
        /// <param name="ttl">Time to live in seconds.</param>
        public static DnsRecord_SPF Parse(string name, byte[] reply, ref int offset, int rdLength, int ttl)
        {
            // SPF RR

            string text = DnsTool.ReadCharacterString(reply, ref offset);

            return(new DnsRecord_SPF(name, text, ttl));
        }
示例#3
0
        /// <summary>
        /// Parses resource record from reply data.
        /// </summary>
        /// <param name="name">DNS domain name that owns a resource record.</param>
        /// <param name="reply">DNS server reply data.</param>
        /// <param name="offset">Current offset in reply data.</param>
        /// <param name="rdLength">Resource record data length.</param>
        /// <param name="ttl">Time to live in seconds.</param>
        public static DnsRecord_CNAME Parse(string name, byte[] reply, ref int offset, int rdLength, int ttl)
        {
            string alias = "";

            if (DnsTool.GetQName(reply, ref offset, ref alias))
            {
                return(new DnsRecord_CNAME(name, alias, ttl));
            }
            else
            {
                throw new ArgumentException("Invalid CNAME resource record data !");
            }
        }
示例#4
0
        /// <summary>
        /// Parses resource record from reply data.
        /// </summary>
        /// <param name="name">DNS domain name that owns a resource record.</param>
        /// <param name="reply">DNS server reply data.</param>
        /// <param name="offset">Current offset in reply data.</param>
        /// <param name="rdLength">Resource record data length.</param>
        /// <param name="ttl">Time to live in seconds.</param>
        public static DnsRecord_NS Parse(string name, byte[] reply, ref int offset, int rdLength, int ttl)
        {
            // Name server name

            string server = "";

            if (DnsTool.GetQName(reply, ref offset, ref server))
            {
                return(new DnsRecord_NS(name, server, ttl));
            }
            else
            {
                throw new ArgumentException("Invalid NS resource record data !");
            }
        }
示例#5
0
        /// <summary>
        /// Parses resource record from reply data.
        /// </summary>
        /// <param name="name">DNS domain name that owns a resource record.</param>
        /// <param name="reply">DNS server reply data.</param>
        /// <param name="offset">Current offset in reply data.</param>
        /// <param name="rdLength">Resource record data length.</param>
        /// <param name="ttl">Time to live in seconds.</param>
        public static DnsRecord_SRV Parse(string name, byte[] reply, ref int offset, int rdLength, int ttl)
        {
            // Priority Weight Port Target

            // Priority
            int priority = reply[offset++] << 8 | reply[offset++];

            // Weight
            int weight = reply[offset++] << 8 | reply[offset++];

            // Port
            int port = reply[offset++] << 8 | reply[offset++];

            // Target
            string target = "";

            DnsTool.GetQName(reply, ref offset, ref target);

            return(new DnsRecord_SRV(name, priority, weight, port, target, ttl));
        }
示例#6
0
        /// <summary>
        /// Parses resource record from reply data.
        /// </summary>
        /// <param name="name">DNS domain name that owns a resource record.</param>
        /// <param name="reply">DNS server reply data.</param>
        /// <param name="offset">Current offset in reply data.</param>
        /// <param name="rdLength">Resource record data length.</param>
        /// <param name="ttl">Time to live in seconds.</param>
        public static DnsRecord_NAPTR Parse(string name, byte[] reply, ref int offset, int rdLength, int ttl)
        {
            /* RFC 3403.
             *  The packet format for the NAPTR record is as follows
             *                                 1  1  1  1  1  1
             *   0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
             |                     ORDER                     |
             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
             |                   PREFERENCE                  |
             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
             |  /                     FLAGS                     /
             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
             |  /                   SERVICES                    /
             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
             |  /                    REGEXP                     /
             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
             |  /                  REPLACEMENT                  /
             |  /                                               /
             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
             */

            int order = reply[offset++] << 8 | reply[offset++];

            int preference = reply[offset++] << 8 | reply[offset++];

            string flags = DnsTool.ReadCharacterString(reply, ref offset);

            string services = DnsTool.ReadCharacterString(reply, ref offset);

            string regexp = DnsTool.ReadCharacterString(reply, ref offset);

            string replacement = "";

            DnsTool.GetQName(reply, ref offset, ref replacement);

            return(new DnsRecord_NAPTR(name, order, preference, flags, services, regexp, replacement, ttl));
        }
示例#7
0
        /// <summary>
        /// Parses resource record from reply data.
        /// </summary>
        /// <param name="name">DNS domain name that owns a resource record.</param>
        /// <param name="reply">DNS server reply data.</param>
        /// <param name="offset">Current offset in reply data.</param>
        /// <param name="rdLength">Resource record data length.</param>
        /// <param name="ttl">Time to live in seconds.</param>
        public static DnsRecord_MX Parse(string name, byte[] reply, ref int offset, int rdLength, int ttl)
        {
            /* RFC 1035	3.3.9. MX RDATA format
             *
             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
             |                  PREFERENCE                   |
             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
             |          /                   EXCHANGE                    /
             |          /                                               /
             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
             |
             |          where:
             |
             |          PREFERENCE
             |                  A 16 bit integer which specifies the preference given to
             |                  this RR among others at the same owner.  Lower values
             |  are preferred.
             |
             |          EXCHANGE
             |              A <domain-name> which specifies a host willing to act as
             |  a mail exchange for the owner name.
             */

            int pref = reply[offset++] << 8 | reply[offset++];

            string server = "";

            if (DnsTool.GetQName(reply, ref offset, ref server))
            {
                return(new DnsRecord_MX(name, pref, server, ttl));
            }
            else
            {
                throw new ArgumentException("Invalid MX resource record data !");
            }
        }