What is the path leading a "DNS query" to GetHostByName()

Kevin Darcy kcd at daimlerchrysler.com
Thu Jul 29 22:16:22 UTC 2004


valere wrote:

>As a newcomer in Dns I would need some explanations to make and send a
>DNS Srv query. My goal is to get the IP_address of a Http server
>furnished by/in the RR (from the DNS server).
>
>
>The way one builds a simple DNS query is very transparent (to me).
>Meaning I use 'gethostbyname' standard API:
>
>
>struct	hostent	*	remoteHost;
>
>	myHost = gethostbyname("OneGivenKnownHttpDomainName"); 
>	IP_Http_Server = myHost->h_addr; 	
>        // Here my goal is reached: IP_Http_Server has been identified
>
>
>I "guess" that the standard DNS query has been (automatically) built
>by "gethostbyname" like this:
>
>QUERY:	 	
>[QNAME="OneGivenKnownHttpDomainName", QCLASS=IN" ...]
>
>and transmitted (how ? Via socket mechanism ?...) to the targeted DNS
>server. Am I wrong ? I see no clear binding between my supposed
>previous "DNS query" form and "gethostbyname" action.
>
>
>Things are getting much more mysterious when intending to proceed with
>a DNS Srv query. I would like to build and send a DNS Srv query this
>way:
>
>QUERY:
>[QNAME="SpecificService._tcp_.OneGivenDomainName", QCLASS="IN",
>QTYPE="SRV"]
>
>But how to transmit such a query to the targeted DNS server ? Still
>Using  "gethostbyname" ? Or Is there another API that would be
>dedicated to that new kind of specific DNS query ? Which one ? Sorry
>for so much naivety.
>
Using the old APIs (try "man resolver"), you could send a query via 
res_query()/res_nquery()/res_search()/res_nsearch()/res_querydomain()/res_nquerydomain() 
(or a combination of res_mkquery()/res_nmkquery() and 
res_send()/res_nsend()) and then parse the answer you get back. Your 
answer-parsing code would have to be very familiar with the layout of a 
DNS answer packet, however, and be aware of label compression.

There are newer APIs that feature more convenient functions like 
getrrsetbyname() (or lwres_getrrsetbyname() in the case of BIND 9), but 
they may or may not be available on your platform (which you didn't 
specify).

                                                                         
                                 - Kevin




More information about the bind-users mailing list