Unix Programming - Hostname Lookup, part 3.

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > May 2005 > Hostname Lookup, part 3.





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Hostname Lookup, part 3.
Daniel Rudy

2005-05-12, 7:56 am


Hopefully, this is a simple question, but how does one do a hostname
lookup to a specific server instead of the configured DNS servers?

I've looked at the source for host, dig, and nslookup, but It's not
really clear as to what it is doing.

--
Daniel Rudy

Email address has been encoded to reduce spam.
Remove all numbers, then remove invalid, email, no, and spam to reply.
Gordon Burditt

2005-05-12, 5:52 pm

>Hopefully, this is a simple question, but how does one do a hostname
>lookup to a specific server instead of the configured DNS servers?
>
>I've looked at the source for host, dig, and nslookup, but It's not
>really clear as to what it is doing.


It is possible (and I've made considerable use of it, for a program
that traces down domains from the root and checks things like all
of the servers for a domain return the same serial number and the
same set of nameservers) to go into the _res structure, change
_res.nscount (probably to 1) and _res.nsaddr_list[] (a struct
sockaddr_in) to point at the nameserver(s) you want to query, after
calling res_init(). You might want to grab the default nameservers
out of _res.nsaddr_list[] first in case there are some queries you
want to use the default list for, like obtaining the IP address of
the server (given as a hostname) you want to query.

When changing _res.nsaddr_list[], be sure to fill in the whole
struct, including the port number.

This probably isn't structly portable, but it works on FreeBSD,
MacOS X, and I think I even got it working under Ultrix. All ran
some version of BIND.

Gordon L. Burditt
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com