備注學院

          LuLu

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            5 隨筆 :: 50 文章 :: 16 評論 :: 0 Trackbacks

          RFC 1035 shows the structure of DNS message as follows

          +---------------------+
          | Header              |
          +---------------------+
          | Question            | the question for the name server
          +---------------------+
          | Answer              | RRs answering the question
          +---------------------+
          | Authority           | RRs pointing toward an authority
          +---------------------+
          | Additional          | RRs holding additional information
          +---------------------+
          

          Obviously queries won't have the answer, authority, and additional fields. Packets are of course UDP and DNS servers feel comfortable to operate on port 53. So the first thing is to send a query containing the hostname.

          The next task is to receive the reply which is expected to contain the information we are expecting. DNS queries are used for a variety of purposes. Apart from getting the ipv4 address of a host we also use DNS for getting the mail exchange/server of a specified domain and etc. All types of queries and response packets are built nearly on the same structure depicted above.

          When a DNS server replies it sends the question as it is along with a bunch of RR's or resource records. All RR's stand in a queue, and certain fields of the header reveal how many of the RR's fall into the answer, authority, and additional categories.

          This is the structure of a DNS header :

          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          | ID                                            |
          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          |QR| Opcode    |AA|TC|RD|RA| Z      |  RCODE    |
          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          |                   QDCOUNT                     |
          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          |                   ANCOUNT                     |
          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          |                   NSCOUNT                     |
          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          |                   ARCOUNT                     |
          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          

          ID :the identifier
          QDCOUNT : how many questions are there in the packet.
          ANCOUNT : how many answers in the RR queue.
          NSCOUNT : Authority RR count
          ARCOUNT : Additional Count
          for explanation of the other fields lookup the RFC
          A DNS packet typically looks like this Header-Query-RR-RR-RR-RR-RR-RR........

          A Query structure looks like this

          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          |                                               |
          /                    QNAME                      /
          /                                               /
          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          |                    QTYPE                      |
          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          |                    QCLASS                     |
          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          

          Note : QNAME is a variable length field to fit the hostname
          QCLASS should be 1 since we are on internet
          QTYPE determines what you want to know ; ipv4 address,mx etc.

          Resource Record(RR) field looks like this

          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          |                                               |
          /                                               /
          /                     NAME                      /
          |                                               |
          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          |                     TYPE                      |
          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          |                     CLASS                     |
          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          |                     TTL                       |
          |                                               |
          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          |                  RDLENGTH                     |
          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
          /                     RDATA                     /
          /                                               /
          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
          

          Note again : NAME and RDATA are variable length field
          Type field tells how RDATA relates to NAME. e.g. if TYPE is 1 then RDATA contains the ipv4 address of the NAME.
          That's all about the structures we need.

          posted on 2008-08-07 23:22 smildlzj 閱讀(370) 評論(0)  編輯  收藏 所屬分類: Web開發
          主站蜘蛛池模板: 温州市| 南澳县| 吴旗县| 太仆寺旗| 阳泉市| 汶上县| 桦川县| 扎赉特旗| 唐山市| 嘉鱼县| 嘉禾县| 平昌县| 武宣县| 安化县| 黎川县| 溧水县| 锡林浩特市| 喀什市| 南溪县| 虞城县| 鹤岗市| 永昌县| 合水县| 高邑县| 娄底市| 隆化县| 久治县| 政和县| 卢龙县| 南昌市| 贵阳市| 柏乡县| 方城县| 普定县| 都兰县| 合水县| 右玉县| 河北区| 平顺县| 疏附县| 黔东|