|I have a project which about dns resolver. I need help about this subject. If somebody have any code in c++ or java, please help.
DNS runs over the UDP protocol, and is used to convert user-friendly host names, e.g., www.anadolu.edu.tr, to IP addresses, called the forward translation, or IP addresses to host names, called the reverse translation.
DNS consists of 2 types of messages: Queries and replies.The message (both query and reply) starts with a 12-byte header. The ¯rst 2 bytes contains the message identi¯er, and is used to match replies with queries. Notice that a real DNS resolver may be handling several queries at the same time. Since
all responses will arrive at the same client port, the resolver needs a way to match responses to queries. The message identifier is used for this purpose. Since the resolver will deal with a single query at any time, you may simply set the identifier field to 1 for all your queries. The next 2 bytes is the flags field, and is divided into numerous pieces.
My code should send the the user friendly adress( www.anadolu.edu.tr) to a name server than if i get the answer i will print the ip adresses to the screen. Also my program shoul send the ip address to a server and get the user friendly name to print.
Type of the message should be like this (Query(i sent) and Reply(server sents) messages are same).
12 BYTES HEADER
0-15 (bits) identification:is used to match replies with queries. It is 1 for this project.
16-31(bits) flag field: id divided into fields like below.
QR is a 1-bit ¯eld: 0 means the message is a query, 1 means it is a response.
OPCODE is a 4-bit field: The normal value is 0 (standard query). Other values are 1 (an inverse query), and 2 (server status request).
AA is a 1-bit flag that means "authoritative answer." If the DNS server is authoritative for the queried host, it sets this bit.
TC is a 1-bit flag that means "truncated." With UDP this means the total size of the reply exceeds 512 bytes, and only the first 512 bytes of the reply was returned.
RD is a 1-bit flag that means "recursion desired." This bit can be set in a query and is then returned in the response. This flag tells the name server to handle the query itlsef, called a recursive query. If the bit is not set, and the requested name server does not have an authoritative answer, the requested name server returns a list of other name servers to contact for the answer. This is called an iterative query.
ZERO There is a 3-bit field that must be 0.
RCODE is a 4-bit field with the return code. The common values are 0 (no error) and 3 (name error). A name error is returned only from an authoritative name server and means the domain speci¯ed in query does not exist.
modified on Thursday, October 29, 2009 8:47 AM