1834022 Members
2496 Online
110063 Solutions
New Discussion

Re: DNS API

 
Rahul Bhagwat
Occasional Contributor

DNS API

I want to bypass the nsswitch.conf and /etc/hosts setting and always get the DNS
reply for resolving a hostname (assuming
/etc/resolv.conf is there).
So I cannot use gethostbyname (which works
with the settings given in /etc/nsswitch.conf)

I tried to use the alternative that I thought
should be used i.e. res_init and res_query.
However it does not seem to work.

Any pointers ?
2 REPLIES 2
Jan de Haas_3
Frequent Advisor

Re: DNS API

Using the config files for nameresolving is the proper way to set up your resolving.

Why would you try to circumvent this mechanism? If it doesn't work properly, just change the configuration and the respective files according to the way you want resolving to work.

Jan.
rick jones
Honored Contributor

Re: DNS API

What do you mean by "it does not seem to work?" Do you not get replies, or do they come from places in nsswitch.conf?

You can use tusc to watch the system calls your application makes when it calls res_init and res_query and see if it opens say nsswitch.conf and/or resolv.conf

To be completely certain that you are sending the DNS query to the server of your choice, you should probably use res_mkquery and then sendto(), then poll() waiting for a reply which you would then recvfrom() and decode yourself.

While it _may_ be possible to go behind res_query's back and redirect it to servers other than those in the nsswitch.conf file, I doubt that such schennanigans would be supported. I do not remember if that ever worked very well with my netperf3 DNS_RR test (ftp.cup.hp.com/dist/networking/benchmarks/netperf/experimental/)
i think there were issues with threads and whether or not you could play with _res directly.

in netperf4 I've gone the res_mkquery etc path. my DNS reply decode requirements for netperf4 DNS query performance are somewhat minimal.

if want you really want is some sort of asynchronous DNS, I believe there are libraries out there for just that thing.
there is no rest for the wicked yet the virtuous have no pillows