tags:

views:

579

answers:

4

Hi.

Is there any way to prevent the gethostbyname() function not to read the nscd cache on Linux?

Thanks in advance!

+1  A: 

don't use nscd? :)

Seriously, if you're relying on gethostbyname() you may want to use libresolv and call res_gethostbyname() instead.

Although that is considered a security flaw by djb at least :)

Consider using the djbdns client library. Very secure, fast, and solid.

John Weldon
Thanks for the tip, but it looks somewhat old (2001)?Also, any idea if it header-level library, or the libraries can be static-linked?
SyBer
Yes it's old, but very solid. I don't know about header level / static linking though, but the source is in the public domain so you could experiment with it.
John Weldon
And, it's no older than gethostbyname() :)
John Weldon
Check out http://www.fefe.de/djb/ - you're looking for dns.a. Static linking is how djb rolls.
Mark Johnson
+2  A: 

Not really an answer, but use getaddrinfo(3) instead :)
As far as nscd is concerned, here's from the nscd.conf(5) manual page:

enable-cache service <yes|no>
    Enables or disables the specified service cache.

You'll have to find out what the correct service for DNS is.

Nikolai N Fetissov
the service would be "hosts"
hayalci
Thanks, it's been a while since I played with those :)
Nikolai N Fetissov
Thanks for the getaddrinfo() - it looks as it not being cached by nscd indeed (at least in man page)?I prefer not to disable the cache at all, as it's only required for particular app.
SyBer
Hi.Can someone provide an example how to use getaddrinfo() to get the IP address?Thanks.
SyBer
Managed to get getaddrinfo() running from here:http://cboard.cprogramming.com/windows-programming/16888-resolving-hostname-using-getaddrinfo-winsock.html
SyBer
A: 

I don't think gethostbyname really caches entries. It's most likely your dns-cache itself.

Suvesh Pratapa
Actually it uses nscd cache. The problem with this caused when the IP changes - it take A LOT (10 min by default) time the nscd refresh the cache and try to resolve it again.
SyBer
A: 

Call res_init() before gethostbyname(). It seems ok.