diff options
Diffstat (limited to 'libc/dns/resolv/res_cache.c')
-rw-r--r-- | libc/dns/resolv/res_cache.c | 67 |
1 files changed, 36 insertions, 31 deletions
diff --git a/libc/dns/resolv/res_cache.c b/libc/dns/resolv/res_cache.c index d68ec3bb0..5a78450f1 100644 --- a/libc/dns/resolv/res_cache.c +++ b/libc/dns/resolv/res_cache.c @@ -28,6 +28,8 @@ #include "resolv_cache.h" #include <resolv.h> +#include <stdarg.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> @@ -45,6 +47,8 @@ #include "resolv_netid.h" #include "res_private.h" +#include "private/libc_logging.h" + /* This code implements a small and *simple* DNS resolver cache. * * It is only used to cache DNS answers for a time defined by the smallest TTL @@ -100,10 +104,6 @@ */ #define CONFIG_ENV "BIONIC_DNSCACHE" -/* entries older than CONFIG_SECONDS seconds are always discarded. - */ -#define CONFIG_SECONDS (60*10) /* 10 minutes */ - /* default number of entries kept in the cache. This value has been * determined by browsing through various sites and counting the number * of corresponding requests. Keep in mind that our framework is currently @@ -152,13 +152,21 @@ /* set to 1 to debug query data */ #define DEBUG_DATA 0 -#undef XLOG #if DEBUG -# include "private/libc_logging.h" -# define XLOG(...) __libc_format_log(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__) +#define __DEBUG__ +#else +#define __DEBUG__ __attribute__((unused)) +#endif -#include <stdio.h> -#include <stdarg.h> +#undef XLOG + +#define XLOG(...) ({ \ + if (DEBUG) { \ + __libc_format_log(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__); \ + } else { \ + ((void)0); \ + } \ +}) /** BOUNDED BUFFER FORMATTING **/ @@ -205,7 +213,7 @@ */ /* add a char to a bounded buffer */ -static char* +char* _bprint_c( char* p, char* end, int c ) { if (p < end) { @@ -220,7 +228,7 @@ _bprint_c( char* p, char* end, int c ) } /* add a sequence of bytes to a bounded buffer */ -static char* +char* _bprint_b( char* p, char* end, const char* buf, int len ) { int avail = end - p; @@ -243,15 +251,15 @@ _bprint_b( char* p, char* end, const char* buf, int len ) } /* add a string to a bounded buffer */ -static char* +char* _bprint_s( char* p, char* end, const char* str ) { return _bprint_b(p, end, str, strlen(str)); } /* add a formatted string to a bounded buffer */ -static char* -_bprint( char* p, char* end, const char* format, ... ) +char* _bprint( char* p, char* end, const char* format, ... ) __DEBUG__; +char* _bprint( char* p, char* end, const char* format, ... ) { int avail, n; va_list args; @@ -278,7 +286,7 @@ _bprint( char* p, char* end, const char* format, ... ) } /* add a hex value to a bounded buffer, up to 8 digits */ -static char* +char* _bprint_hex( char* p, char* end, unsigned value, int numDigits ) { char text[sizeof(unsigned)*2]; @@ -291,7 +299,7 @@ _bprint_hex( char* p, char* end, unsigned value, int numDigits ) } /* add the hexadecimal dump of some memory area to a bounded buffer */ -static char* +char* _bprint_hexdump( char* p, char* end, const uint8_t* data, int datalen ) { int lineSize = 16; @@ -330,20 +338,17 @@ _bprint_hexdump( char* p, char* end, const uint8_t* data, int datalen ) } /* dump the content of a query of packet to the log */ -static void -XLOG_BYTES( const void* base, int len ) +void XLOG_BYTES( const void* base, int len ) __DEBUG__; +void XLOG_BYTES( const void* base, int len ) { - char buff[1024]; - char* p = buff, *end = p + sizeof(buff); - - p = _bprint_hexdump(p, end, base, len); - XLOG("%s",buff); -} + if (DEBUG_DATA) { + char buff[1024]; + char* p = buff, *end = p + sizeof(buff); -#else /* !DEBUG */ -# define XLOG(...) ((void)0) -# define XLOG_BYTES(a,b) ((void)0) -#endif + p = _bprint_hexdump(p, end, base, len); + XLOG("%s",buff); + } +} __DEBUG__ static time_t _time_now( void ) @@ -1090,7 +1095,7 @@ answer_getTTL(const void* answer, int answerlen) XLOG("ns_parserr failed. %s\n", strerror(errno)); } - XLOG("TTL = %d\n", result); + XLOG("TTL = %lu\n", result); return result; } @@ -1453,7 +1458,7 @@ _dump_answer(const void* answer, int answerlen) char* buf; int fileLen; - fp = fopen("/data/reslog.txt", "w+"); + fp = fopen("/data/reslog.txt", "w+e"); if (fp != NULL) { statep = __res_get_state(); @@ -1949,7 +1954,7 @@ _resolv_set_nameservers_for_net(unsigned netid, const char** servers, int numser hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; /*dummy*/ hints.ai_flags = AI_NUMERICHOST; - sprintf(sbuf, "%u", NAMESERVER_PORT); + snprintf(sbuf, sizeof(sbuf), "%u", NAMESERVER_PORT); index = 0; for (i = 0; i < numservers && i < MAXNS; i++) { |