1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## 18_dns_retry.dpatch by Fabian Keil <fk@fabiankeil.de>
4 ## All lines beginning with `## DP:' are a description of the patch.
5 ## DP: Retries DNS queries 10 times before giving up.
6 ## DP: Extracted from http://www.fabiankeil.de/sourcecode/privoxy/
9 diff -urNad privoxy~/jbsockets.c privoxy/jbsockets.c
10 --- privoxy~/jbsockets.c
11 +++ privoxy/jbsockets.c
14 struct sockaddr_in inaddr;
15 struct hostent *hostp;
16 + unsigned int dns_retries = 0;
17 #if defined(HAVE_GETHOSTBYNAME_R_6_ARGS) || defined(HAVE_GETHOSTBYNAME_R_5_ARGS) || defined(HAVE_GETHOSTBYNAME_R_3_ARGS)
18 struct hostent result;
19 #if defined(HAVE_GETHOSTBYNAME_R_6_ARGS) || defined(HAVE_GETHOSTBYNAME_R_5_ARGS)
21 if ((inaddr.sin_addr.s_addr = inet_addr(host)) == -1)
23 #if defined(HAVE_GETHOSTBYNAME_R_6_ARGS)
24 - gethostbyname_r(host, &result, hbuf,
25 - HOSTENT_BUFFER_SIZE, &hostp, &thd_err);
26 + while ( gethostbyname_r(host, &result, hbuf,
27 + HOSTENT_BUFFER_SIZE, &hostp, &thd_err)
28 + && (thd_err == TRY_AGAIN) && (dns_retries++ < 10) )
30 + log_error(LOG_LEVEL_ERROR, "Timeout #%u while trying to resolve %s. Trying again.",
33 #elif defined(HAVE_GETHOSTBYNAME_R_5_ARGS)
34 hostp = gethostbyname_r(host, &result, hbuf,
35 HOSTENT_BUFFER_SIZE, &thd_err);
39 pthread_mutex_lock(&gethostbyname_mutex);
40 - hostp = gethostbyname(host);
41 + while ( NULL == (hostp = gethostbyname(host))
42 + && (h_errno == TRY_AGAIN) && (dns_retries++ < 10) )
44 + log_error(LOG_LEVEL_ERROR, "Timeout #%u while trying to resolve %s. Trying again.",
47 pthread_mutex_unlock(&gethostbyname_mutex);
49 - hostp = gethostbyname(host);
50 + while ( NULL == (hostp = gethostbyname(host))
51 + && (h_errno == TRY_AGAIN) && (dns_retries++ < 10) )
53 + log_error(LOG_LEVEL_ERROR, "%u. timeout while trying to resolve %s. Trying again.",
56 #endif /* def HAVE_GETHOSTBYNAME_R_(6|5|3)_ARGS */
58 * On Mac OSX, if a domain exists but doesn't have a type A