備注學院

          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開發
          主站蜘蛛池模板: 嘉鱼县| 武汉市| 公主岭市| 临西县| 大姚县| 商都县| 大连市| 景泰县| 泰和县| 台中市| 南雄市| 桃源县| 辰溪县| 东兰县| 桂东县| 安龙县| 定远县| 鹤山市| 衡水市| 阳春市| 南京市| 泊头市| 大冶市| 贵定县| 大丰市| 湘潭县| 广宗县| 新野县| 和平县| 台江县| 镇雄县| 北辰区| 扎鲁特旗| 阳山县| 高密市| 建瓯市| 蚌埠市| 新巴尔虎左旗| 德保县| 辽宁省| 体育|