Hi all,

I'd like to get the TTL value for a DNS request. I looked at what it
would take to add this to struct ub_result and it doesn't look too
difficult - patch attached.

Is this the right approach? Or should I use ldns to parse the raw
packet bytes to get the ttl?

Thanks,
David
diff -Naur unbound-svn/libunbound/libworker.c unbound-svn/libunbound/libworker.c
--- unbound-svn/libunbound/libworker.c  2009-11-13 13:49:03.000000000 -0700
+++ unbound-svn/libunbound/libworker.c  2009-11-13 14:17:26.000000000 -0700
@@ -393,11 +393,13 @@
        } else  res->canonname = NULL;
        res->data = (char**)calloc(data->count+1, sizeof(char*));
        res->len = (int*)calloc(data->count+1, sizeof(int));
-       if(!res->data || !res->len)
+       res->ttl = (unsigned*)calloc(data->count+1, sizeof(unsigned));
+       if(!res->data || !res->len || !res->ttl)
                return 0; /* out of memory */
        for(i=0; i<data->count; i++) {
                /* remove rdlength from rdata */
                res->len[i] = (int)(data->rr_len[i] - 2);
+               res->ttl[i] = data->rr_ttl[i];
                res->data[i] = memdup(data->rr_data[i]+2, (size_t)res->len[i]);
                if(!res->data[i])
                        return 0; /* out of memory */
diff -Naur unbound-svn/libunbound/unbound.h unbound-svn/libunbound/unbound.h
--- unbound-svn/libunbound/unbound.h    2009-11-13 13:49:03.000000000 -0700
+++ unbound-svn/libunbound/unbound.h    2009-11-13 14:18:55.000000000 -0700
@@ -126,6 +126,9 @@
        /** the length in bytes of the data items, len[i] for data[i] */
        int* len;
 
+       /** TTL (in seconds like time()) of rdata items */
+       unsigned* ttl;
+
        /** 
         * canonical name for the result (the final cname). 
         * zero terminated string.
_______________________________________________
Unbound-users mailing list
[email protected]
http://unbound.nlnetlabs.nl/mailman/listinfo/unbound-users

Reply via email to