diff options
Diffstat (limited to 'tools/dnssec/dns-wire2text.c')
-rw-r--r-- | tools/dnssec/dns-wire2text.c | 62 |
1 files changed, 3 insertions, 59 deletions
diff --git a/tools/dnssec/dns-wire2text.c b/tools/dnssec/dns-wire2text.c index 896fc6e..1443bc4 100644 --- a/tools/dnssec/dns-wire2text.c +++ b/tools/dnssec/dns-wire2text.c @@ -9,6 +9,7 @@ #include <errno.h> #include <getdns/getdns.h> #include <getdns/getdns_extra.h> +#include "common.h" #undef DEBUG @@ -34,63 +35,6 @@ hd(const char *buf, size_t buf_len) #define hd(a,b) #endif -#define CHUNKSIZE 4096 - -static size_t -read_inbuf(FILE *infp, uint8_t **bufp_out) -{ - size_t nread = 0; - uint8_t *wirebuf = malloc(CHUNKSIZE); - int chunks = 1; - - if (wirebuf == NULL) - goto out; - - while (1) - { - size_t n = fread(wirebuf + nread, 1, CHUNKSIZE, infp); - nread += n; - if (n < CHUNKSIZE) - break; /* Done. */ - - wirebuf = realloc(wirebuf, ++chunks * CHUNKSIZE); - if (wirebuf == NULL) - break; - } - - out: - if (bufp_out != NULL) - *bufp_out = wirebuf; - return nread; -} - -static getdns_return_t -wire_rrs2list(const uint8_t *buf, size_t buf_len, getdns_list **list_out) -{ - getdns_return_t r = GETDNS_RETURN_GOOD; - getdns_list *list = getdns_list_create(); - getdns_dict *dict = NULL; - size_t rr_count = 0; - - if (list == NULL) - return GETDNS_RETURN_MEMORY_ERROR; - while (buf_len > 0) - { - r = getdns_wire2rr_dict_scan(&buf, &buf_len, &dict); - if (r) - break; - r = getdns_list_set_dict(list, rr_count, dict); - getdns_dict_destroy(dict); /* The list has a copy. */ - if (r) - break; - rr_count++; - } - - if (list_out) - *list_out = list; - return r; -} - int main(int argc, char *argv[]) { @@ -108,10 +52,10 @@ main(int argc, char *argv[]) /* Read RRs in wire format. */ uint8_t *inbuf = NULL; - size_t inbuf_len = read_inbuf(infp, &inbuf); + size_t inbuf_len = read_buffer(infp, &inbuf, 0); if (inbuf == NULL) { - perror("read_inbuf"); + perror("read_buffer"); return errno; } if (infp != stdin) |