summaryrefslogtreecommitdiff
path: root/tools/dnssec/dns-wire2text.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2016-03-30 21:35:31 +0200
committerLinus Nordberg <linus@nordu.net>2016-03-30 21:35:31 +0200
commitb69ff1c846250939de3e4f32ff4d07d6ee415009 (patch)
tree4b5755c39fdac519cb9b878d011ee33a729b8a62 /tools/dnssec/dns-wire2text.c
parent8106050f24d1552f9fe9f0f1521eb3068de08ea4 (diff)
Add validatechain.c and move some code to common.c.
dns-net2wire.c is nothing but an ugly hack on top of getdns_query.c making it save answer, validation_chain and trust anchors to three separate files. Used for testing purposes. validatechain takes the above mentioned three files as input and performs DNSSEC validation.
Diffstat (limited to 'tools/dnssec/dns-wire2text.c')
-rw-r--r--tools/dnssec/dns-wire2text.c62
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)