Преглед на файлове

* Fixed TTL issue

svn: 1424
Bryan Drewery преди 21 години
родител
ревизия
00aefd91e9
променени са 1 файла, в които са добавени 8 реда и са изтрити 7 реда
  1. 8 7
      src/adns.c

+ 8 - 7
src/adns.c

@@ -10,6 +10,7 @@
 
 typedef struct {
 	char **list;
+	time_t ttl;
 	int len;
 } dns_answer_t;
 
@@ -515,7 +516,7 @@ static void cache_del(int id)
 	cache = (dns_cache_t *) realloc(cache, (ncache+1)*sizeof(*cache));
 }
 
-static void cache_add(const char *query, dns_answer_t *answer, time_t ttl)
+static void cache_add(const char *query, dns_answer_t *answer)
 {
 	int i;
 
@@ -525,7 +526,7 @@ static void cache_add(const char *query, dns_answer_t *answer, time_t ttl)
 	answer_init(&cache[ncache].answer);
         for (i = 0; i < answer->len; i++)
 		answer_add(&cache[ncache].answer, answer->list[i]);
-	cache[ncache].expiretime = now + ttl;
+	cache[ncache].expiretime = now + answer->ttl;
 	ncache++;
 }
 
@@ -693,7 +694,6 @@ static void parse_reply(char *response, int nbytes)
 	char result[512];
 	unsigned char *ptr;
 	int i;
-	time_t ttl = 0;
 
 	ptr = (unsigned char *) response;
 	memcpy(&header, ptr, 12);
@@ -729,8 +729,9 @@ static void parse_reply(char *response, int nbytes)
 		reply.type = ntohs(reply.type);
 		reply.rdlength = ntohs(reply.rdlength);
 		reply.ttl = ntohl(reply.ttl);
+
 		/* Save the lowest ttl */
-		if (reply.ttl && (reply.ttl < ttl)) ttl = reply.ttl;
+		if (reply.ttl && ((!q->answer.ttl) || (q->answer.ttl > reply.ttl))) q->answer.ttl = reply.ttl;
 		ptr += 10;
 		if (reply.type == 1) {
 			/*fprintf(fp, "ipv4 reply\n");*/
@@ -770,9 +771,9 @@ static void parse_reply(char *response, int nbytes)
 			}
 			ptr = (unsigned char *) placeholder;
 		}
+
 		ptr += reply.rdlength;
 	}
-
 	q->remaining--;
 	/* Don't continue if we haven't gotten all expected replies. */
 	if (q->remaining > 0) return;
@@ -780,8 +781,8 @@ static void parse_reply(char *response, int nbytes)
 	/* Ok, we have, so now issue the callback with the answers. */
 	if (prev) prev->next = q->next;
 	else query_head = q->next;
-	cache_add(q->query, &q->answer, ttl);
-sdprintf("ncache is now: %d", ncache);
+
+	cache_add(q->query, &q->answer);
 
 	q->callback(q->client_data, q->query, q->answer.list);
 	answer_free(&q->answer);