備注學院

          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 閱讀(366) 評論(0)  編輯  收藏 所屬分類: Web開發
          主站蜘蛛池模板: 郴州市| 新竹市| 台中市| 凌云县| 蓬安县| 兴山县| 长顺县| 密山市| 绍兴县| 平遥县| 宿州市| 五原县| 榆林市| 黔江区| 崇左市| 德安县| 香港| 林口县| 苗栗市| 正阳县| 体育| 五指山市| 苍南县| 大荔县| 太仆寺旗| 汉沽区| 淄博市| 新津县| 顺义区| 五原县| 福鼎市| 清丰县| 儋州市| 和田县| 神木县| 西畴县| 镇沅| 云浮市| 吉安县| 新闻| 三亚市|