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