summaryrefslogtreecommitdiff
path: root/tools/dnssec/net2wire.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/dnssec/net2wire.c')
-rw-r--r--tools/dnssec/net2wire.c105
1 files changed, 2 insertions, 103 deletions
diff --git a/tools/dnssec/net2wire.c b/tools/dnssec/net2wire.c
index f97483f..bbf1269 100644
--- a/tools/dnssec/net2wire.c
+++ b/tools/dnssec/net2wire.c
@@ -22,108 +22,7 @@
#include <getdns/getdns_ext_libevent.h>
#include <event2/event.h>
-static int debug = 1;
-
-static getdns_return_t
-dump_reply(FILE *fp, getdns_dict *reply, const char *section_name)
-{
- getdns_list *section = NULL;
- size_t section_len = -1;
- getdns_return_t r;
- uint8_t res_buf[4096], *res = NULL;
- size_t res_len = sizeof(res_buf);
-
- r = getdns_dict_get_list(reply, section_name, &section);
- if (r) {
- fprintf(stderr,
- "unable to get section \"%s\" from reply\n",
- section_name);
- return r;
- }
-
- r = getdns_list_get_length(section, &section_len);
- if (r) {
- fprintf(stderr, "unable to get length of section\n");
- return r;
- }
-
- for (size_t j = 0; j < section_len; j++) {
- getdns_dict *rr = NULL;
-
- r = getdns_list_get_dict(section, j , &rr);
- if (r) {
- fprintf(stderr, "unable to get rr from entry "
- "%d: %d\n", j, r);
- return r;
- }
-
- r = getdns_rr_dict2wire(rr, &res, &res_len);
- if (r) {
- fprintf(stderr,
- "unable to convert entry %d "
- "to wire format: %d\n", j, r);
- return r;
- }
-
- if (0 && debug) {
- char *s = getdns_pretty_print_dict(rr);
- puts(s);
- free(s);
- }
-
- if (fwrite(res, 1, res_len, fp) != res_len) {
- fprintf(stderr,
- "unable to write buffer to file: %s\n",
- strerror(errno));
- return -errno;
- }
-
- free(res);
- }
-
- return 0;
-}
-
-int
-dump_tree(FILE *fp, const getdns_dict *response, const char *tree_name)
-{
- getdns_return_t r;
- getdns_list *tree = NULL;
- size_t n_replies = -1;
-
- r = getdns_dict_get_list(response, tree_name, &tree);
- if (r) {
- fprintf(stderr, "unable to get tree %s\n", tree_name);
- return r;
- }
-
- r = getdns_list_get_length(tree, &n_replies);
- if (r) {
- fprintf(stderr, "unable to get number of replies\n");
- return r;
- }
-
- for (size_t i = 0; i < n_replies; i++) {
- getdns_dict *reply = NULL;
-
- r = getdns_list_get_dict(tree, i, &reply);
- if (r) {
- fprintf(stderr, "unable to get reply %d from tree\n", i);
- return r;
- }
-
- if (debug) {
- char *s = getdns_pretty_print_dict(reply);
- printf("Pretty-printing reply #%d:%s\n", i, s);
- free(s);
- }
-
- dump_reply(fp, reply, "answer");
- }
-
- return 0;
-}
-
+#include "common.h"
/* Set up the callback function, which will also do the processing of the results */
void callback(getdns_context *context,
@@ -171,7 +70,7 @@ void callback(getdns_context *context,
static char *TREES[] = {"replies_tree", "validation_chain"};
static const int TREES_LEN = 2;
for (int i = 0; i < TREES_LEN; i++) {
- if (dump_tree(treeoutfp, response, TREES[i]))
+ if (dump_tree(treeoutfp, response, TREES[i], "answer"))
fprintf(stderr, "Could not dump %s to file\n", TREES[i]);
else if ((r = getdns_dict_get_bindata(response, "/just_address_answers/0/address_data", &address_data)))