cache: cache rdata of SRV-records as well
[project/mdnsd.git] / cache.c
diff --git a/cache.c b/cache.c
index f2687e115b50a386dfdc50e1abf9210d5d028e5c..7c7a8fba52858cc573100f9d1ff8f6713722cbce 100644 (file)
--- a/cache.c
+++ b/cache.c
@@ -63,7 +63,7 @@ cache_service_free(struct cache_service *s)
 static int
 cache_is_expired(time_t t, uint32_t ttl, int frac)
 {
-       if (time(NULL) - t >= ttl * frac / 100)
+       if (monotonic_time() - t >= ttl * frac / 100)
                return 1;
 
        return 0;
@@ -142,7 +142,7 @@ cache_service(struct interface *iface, char *entry, int hlen, int ttl)
        avl_for_each_element_safe(&services, s, avl, t)
                if (!strcmp(s->entry, entry)) {
                        s->refresh = 50;
-                       s->time = time(NULL);
+                       s->time = monotonic_time();
                        return s;
                }
 
@@ -151,7 +151,7 @@ cache_service(struct interface *iface, char *entry, int hlen, int ttl)
                &host_buf, hlen ? hlen + 1 : 0);
 
        s->avl.key = s->entry = strcpy(entry_buf, entry);
-       s->time = time(NULL);
+       s->time = monotonic_time();
        s->ttl = ttl;
        s->iface = iface;
        s->refresh = 50;
@@ -268,6 +268,14 @@ cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struc
                        return;
 
                port = be16_to_cpu(dsd->port);
+               memcpy(rdata_buffer, dsd, sizeof(*dsd));
+               if (dn_expand(base, base + blen, (const uint8_t*)&dsd[1],
+                               &rdata_buffer[sizeof(*dsd)], MAX_DATA_LEN - sizeof(*dsd)) < 0) {
+                       perror("process_answer/dn_expand");
+                       return;
+               }
+               dlen = sizeof(*dsd) + strlen(&rdata_buffer[sizeof(*dsd)]) + 1;
+               rdata = (uint8_t*)rdata_buffer;
                break;
 
        case TYPE_TXT:
@@ -311,7 +319,7 @@ cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struc
        if (r) {
                if (!a->ttl) {
                        DBG(1, "D -> %s %s ttl:%d\n", dns_type_string(r->type), r->record, r->ttl);
-                       r->time = time(0) + 1 - r->ttl;
+                       r->time = monotonic_time() + 1 - r->ttl;
                } else {
                        r->ttl = a->ttl;
                        DBG(1, "A -> %s %s ttl:%d\n", dns_type_string(r->type), r->record, r->ttl);
@@ -332,7 +340,7 @@ cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struc
        r->ttl = a->ttl;
        r->port = port;
        r->rdlength = dlen;
-       r->time = time(NULL);
+       r->time = monotonic_time();
        r->iface = iface;
 
        if (tlen)