| Author |
Specifying nameservers with gethostbyname
|
|
| Jeff Rodriguez 2004-01-23, 5:27 pm |
| Is there any way to specify what nameservers will be used when a call to
gethostbyname is called? This must be done from within the code, not by
modifying /etc/resolv.conf.
I'm about to tear into the source code for dig and I would much rather avoid
that if possible 
Jeff
| |
| Michael Fuhr 2004-01-23, 5:27 pm |
| Jeff Rodriguez <newsgroup1@gurugeek.EXAMPLENOSPAM.com> writes:
quote:
> Is there any way to specify what nameservers will be used when a call to
> gethostbyname is called? This must be done from within the code, not by
> modifying /etc/resolv.conf.
You don't say what kind of system you're using, but programs can
usually tweak the resolver's behavior by calling res_init() and
then modifying the global _res structure before calling any resolver
functions like gethostbyname(). _res is a struct __res_state, which
should be defined in <resolv.h>. The number of nameservers and
their IP addresses are in the nscount and nsaddr_list fields.
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
| |
| David Schwartz 2004-01-23, 5:27 pm |
|
"Jeff Rodriguez" <newsgroup1@gurugeek.EXAMPLENOSPAM.com> wrote in message
news:deVyb.22313$o9.6964@fed1read07...
quote:
> Is there any way to specify what nameservers will be used when a call to
> gethostbyname is called? This must be done from within the code, not by
> modifying /etc/resolv.conf.
>
> I'm about to tear into the source code for dig and I would much rather
avoidquote:
> that if possible 
Who says 'gethostbyname' even uses nameservers? The purpose of the
'gethostbyname' call is to resolve a name to a host by the system's default
mechanism or mechanisms.
DS
| |
| Jeff Rodriguez 2004-01-23, 5:27 pm |
| David Schwartz wrote:quote:
> "Jeff Rodriguez" <newsgroup1@gurugeek.EXAMPLENOSPAM.com> wrote in message
> news:deVyb.22313$o9.6964@fed1read07...
>
>
>
> avoid
>
>
>
> Who says 'gethostbyname' even uses nameservers? The purpose of the
> 'gethostbyname' call is to resolve a name to a host by the system's default
> mechanism or mechanisms.
>
> DS
>
>
Target systems are BSD or Linux. Is there a better way than copying what dig does?
Jeff
| |
| David Schwartz 2004-01-23, 5:27 pm |
|
"Jeff Rodriguez" <newsgroup1@gurugeek.EXAMPLENOSPAM.com> wrote in message
news:7f2zb.22453$o9.3830@fed1read07...
quote:
default[QUOTE][color=darkred]
[QUOTE][color=darkred]
> Target systems are BSD or Linux. Is there a better way than copying what
dig does?
It really depends what you're trying to do. Do you want to do an
arbitrary query to the nameserver of your choice and process the results in
a custom way? Do you want to be overrideable by '/etc/hosts'? What if the
local machine normally resolves hosts using something like NIS+?
You should code exactly what you want. ;)
DS
|
|
|
|