wahern / dns

dns.c: Single file non-blocking DNS C library without callbacks or external dependencies.
http://25thandclement.com/~william/projects/dns.c.html
MIT License
256 stars 65 forks source link

Cache is being ignored #13

Open sjakub opened 8 years ago

sjakub commented 8 years ago

This is probably caused by the fact that I am not using the APIs properly, but I cannot get the cache to work... at all.

I use the resolver generated using dns_res_open(), passing a cache object to it. Then I use dns_ai_open() and dns_ai_nextent(). Everything works fine, except the cache is getting ignored...

Nothing new is added to it, when I dump it to a file it's empty. When I manually create a cache, using data generated by 'cache' tool, it is loaded, but then it is getting ignored and still does the DNS query.

Is there an example how to add cache support to the resolver? Thanks!

wahern commented 8 years ago

1) Be sure to include the letter "c" in the .lookup field of the resconf object. You can do that manually or by including the word "cache" in the "lookup" line in the resolv.conf file used to initialize the object. The order in which it appears controls when it's queried.

(/etc/resolv.conf "lookup ..." is the BSD equivalent to Linux's "hosts: ..." line in /etc/nsswitch.conf, though dns.c's /etc/nsswitch.conf parser doesn't recognize the "cache" keyword.)

2) The cache API in dns.h is intended only for querying; there's no handler defined to insert new records through the API. That currently has to be done in the application using a private interface to its cache implementation after processing the result of dns_res_fetch.

The cache implementation in src/cache.h and src/cache.c was written principally for use by the RFC 4408 (SPF) test suite implemented in regress/rfc4408-tests.c.