diff options
author | Daniel Stenberg <daniel@haxx.se> | 2002-01-03 10:22:59 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2002-01-03 10:22:59 +0000 |
commit | 6de7dc5879b3605a180dafa05f792f132eafdcaa (patch) | |
tree | 9684f8c2427082965204ee5589a2ee1e5dc6191d /lib/hostip.c | |
parent | 6aaee5f23bdc75826a733e40335078b97bfe1967 (diff) |
Sterling Hughes' provided initial DNS cache source code.
Diffstat (limited to 'lib/hostip.c')
-rw-r--r-- | lib/hostip.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/hostip.c b/lib/hostip.c index 86faa117a..db02b8681 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -58,6 +58,7 @@ #include "urldata.h" #include "sendf.h" #include "hostip.h" +#include "hash.h" #if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL) #include "inet_ntoa_r.h" @@ -68,6 +69,38 @@ #include "memdebug.h" #endif +static curl_hash hostname_cache; + +void Curl_host_cache_init(void) +{ + curl_hash_init(&hostname_cache, 7, Curl_freeaddrinfo); +} + +void Curl_host_cache_dtor(void) +{ + curl_hash_clean(&hostname_cache); +} + + +Curl_addrinfo *Curl_resolv(struct SessionHandle *data, + char *hostname, + int port, + char **bufp) +{ + Curl_addrinfo *addr = NULL; + size_t hostname_len = strlen(hostname)+1; + + if (curl_hash_find(&hostname_cache, hostname, hostname_len, (void **) &addr)) + return addr; + + addr = Curl_getaddrinfo(data, hostname, port, bufp); + if (!addr) + return NULL; + + curl_hash_add(&hostname_cache, hostname, hostname_len, (const void *) addr); + return addr; +} + /* * This is a wrapper function for freeing name information in a protocol * independent way. This takes care of using the appropriate underlaying |