aboutsummaryrefslogtreecommitdiffstats
path: root/libc/netbsd/resolv/res_send.c
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-02-19 10:57:29 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-02-19 10:57:29 -0800
commit6f04a0f4c72acff80dad04828cb69ef67fa609d1 (patch)
tree915db7d93cb742f72b5d3819e69f48cb29c40a15 /libc/netbsd/resolv/res_send.c
parent2489551343aa89fc539f369f7689c941b78c08d1 (diff)
downloadandroid_bionic-6f04a0f4c72acff80dad04828cb69ef67fa609d1.tar.gz
android_bionic-6f04a0f4c72acff80dad04828cb69ef67fa609d1.tar.bz2
android_bionic-6f04a0f4c72acff80dad04828cb69ef67fa609d1.zip
auto import from //branches/cupcake/...@132276
Diffstat (limited to 'libc/netbsd/resolv/res_send.c')
-rw-r--r--libc/netbsd/resolv/res_send.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/libc/netbsd/resolv/res_send.c b/libc/netbsd/resolv/res_send.c
index 24b740a2c..3aca760fe 100644
--- a/libc/netbsd/resolv/res_send.c
+++ b/libc/netbsd/resolv/res_send.c
@@ -81,6 +81,9 @@ __RCSID("$NetBSD: res_send.c,v 1.9 2006/01/24 17:41:25 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
+/* set to 1 to use our small/simple/limited DNS cache */
+#define USE_RESOLV_CACHE 1
+
/*
* Send query to name server and wait for reply.
*/
@@ -111,6 +114,10 @@ __RCSID("$NetBSD: res_send.c,v 1.9 2006/01/24 17:41:25 christos Exp $");
#include <isc/eventlib.h>
+#if USE_RESOLV_CACHE
+# include <resolv_cache.h>
+#endif
+
#ifndef DE_CONST
#define DE_CONST(c,v) v = ((c) ? \
strchr((const void *)(c), *(const char *)(const void *)(c)) : NULL)
@@ -344,12 +351,17 @@ res_queriesmatch(const u_char *buf1, const u_char *eom1,
return (1);
}
+
int
res_nsend(res_state statp,
const u_char *buf, int buflen, u_char *ans, int anssiz)
{
int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;
char abuf[NI_MAXHOST];
+#if USE_RESOLV_CACHE
+ struct resolv_cache* cache;
+ ResolvCacheStatus cache_status = RESOLV_CACHE_UNSUPPORTED;
+#endif
if (statp->nscount == 0) {
errno = ESRCH;
@@ -365,6 +377,20 @@ res_nsend(res_state statp,
gotsomewhere = 0;
terrno = ETIMEDOUT;
+#if USE_RESOLV_CACHE
+ cache = __get_res_cache();
+ if (cache != NULL) {
+ int anslen = 0;
+ cache_status = _resolv_cache_lookup(
+ cache, buf, buflen,
+ ans, anssiz, &anslen);
+
+ if (cache_status == RESOLV_CACHE_FOUND) {
+ return anslen;
+ }
+ }
+#endif
+
/*
* If the ns_addr_list in the resolver context has changed, then
* invalidate our cached copy and the associated timing data.
@@ -534,6 +560,12 @@ res_nsend(res_state statp,
(stdout, "%s", ""),
ans, (resplen > anssiz) ? anssiz : resplen);
+#if USE_RESOLV_CACHE
+ if (cache_status == RESOLV_CACHE_NOTFOUND) {
+ _resolv_cache_add(cache, buf, buflen,
+ ans, resplen);
+ }
+#endif
/*
* If we have temporarily opened a virtual circuit,
* or if we haven't been asked to keep a socket open,