備注學(xué)院

          LuLu

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            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開發(fā)
          主站蜘蛛池模板: 文山县| 青州市| 乐至县| 于都县| 贵港市| 涿州市| 镇平县| 达拉特旗| 曲麻莱县| 桂林市| 青河县| 西城区| 庄河市| 卫辉市| 东阿县| 渝中区| 香格里拉县| 舞阳县| 桦川县| 苏尼特右旗| 赣州市| 育儿| 外汇| 申扎县| 漳州市| 奇台县| 深圳市| 枝江市| 互助| 边坝县| 额济纳旗| 四平市| 渭源县| 彰武县| 丰顺县| 女性| 长宁区| 建宁县| 成武县| 达孜县| 工布江达县|