[Unbound-users] get ttl in libunbound?
David Hubbard
david.c.hubbard at gmail.com
Sat Nov 14 05:08:25 UTC 2009
Hi all,
This patch adds a call to free(ttl) that balances the call to
calloc(). The previous patch creates a memory leak.
This patch also moves 'unsigned *ttl' to the end of struct ub_result,
so that binaries linked against libunbound.so will still work.
David
On Fri, Nov 13, 2009 at 4:18 PM, David Hubbard
<david.c.hubbard at gmail.com> wrote:
> Hi Ondrej,
>
> On Fri, Nov 13, 2009 at 4:10 PM, Ondřej Surý <ondrej at sury.org> wrote:
>> On Fri, Nov 13, 2009 at 23:55, David Hubbard <david.c.hubbard at gmail.com> wrote:
>>> 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.
>>
>> Please don't change the existing API. In this case it could be solved
>> just by recompiling all dependant programs, but generally changing
>> existing API causes a lot of troubles (beware not adding new functions
>> and data types - but really changing existing functions).
>
> I agree - this patch breaks the ABI. I don't think this is an urgent
> matter, so would it be acceptable to put this in the queue for
> whenever the next major API changes happen?
>
> I do want to use the full validating resolver (especially dnssec). I
> also find the libunbound interface simpler, so my code is easy to
> read. I'm trying to replace code that used a different dns resolver
> library that has gone dormant and doesn't have dnssec support.
>
> One possibility is to place unsigned* ttl at the end of struct
> ub_result - then existing applications would not break. I think it
> "looks nicer" where it is. Either way, it doesn't really matter.
>
> Thanks for your consideration,
> David
>
-------------- next part --------------
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
@@ -192,6 +189,9 @@
* Is NULL if the result is not bogus.
*/
char* why_bogus;
+
+ /** TTL (in seconds like time()) of rdata items */
+ unsigned* ttl;
};
/**
diff -Naur unbound-svn/libunbound/unbound.h unbound-svn/libunbound/unbound.h
--- unbound-svn/libunbound/libunbound.c 2009-11-13 13:49:03.000000000 -0700
+++ unbound-svn/libunbound/libunbound.c 2009-11-13 14:18:55.000000000 -0700
@@ -690,6 +690,7 @@
free(*p);
free(result->data);
free(result->len);
+ free(result->ttl);
free(result->answer_packet);
free(result->why_bogus);
free(result);
More information about the Unbound-users
mailing list