From 57690b920ded6590c6109752ca05faf47f2e2795 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Sun, 3 Apr 2016 18:53:38 +0200 Subject: Add dns-text2wire. --- tools/dnssec/Makefile | 4 +++- tools/dnssec/dns-text2wire.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tools/dnssec/dns-text2wire.c diff --git a/tools/dnssec/Makefile b/tools/dnssec/Makefile index 7c3f2fb..77d2081 100644 --- a/tools/dnssec/Makefile +++ b/tools/dnssec/Makefile @@ -1,10 +1,12 @@ CFLAGS = -Wall -g -std=c99 CFLAGS_PEDANTIC = -pedantic -Werror -Wextra -all: dns-net2wire dns-wire2text net2wire validatechain +all: dns-net2wire dns-wire2text dns-text2wire net2wire validatechain dns-net2wire: dns-net2wire.c common.c $(CC) $(CFLAGS) -o $@ -lgetdns -lgetdns_ext_event -levent $^ +dns-text2wire: dns-text2wire.c + $(CC) $(CFLAGS) -o $@ -lgetdns $^ dns-wire2text: dns-wire2text.c common.c $(CC) $(CFLAGS) $(CFLAGS_PEDANTIC) -o $@ -lgetdns -lgetdns_ext_event -levent $^ validatechain: validatechain.c common.c diff --git a/tools/dnssec/dns-text2wire.c b/tools/dnssec/dns-text2wire.c new file mode 100644 index 0000000..99d418f --- /dev/null +++ b/tools/dnssec/dns-text2wire.c @@ -0,0 +1,44 @@ +/* + Read RR's in zone file format and write them in wire format. +*/ + +#include +#include +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + FILE *fp = stdin; + if (argc > 1) + fp = fopen(argv[1], "r"); + assert(fp); + getdns_list *list = NULL; + getdns_return_t r = getdns_fp2rr_list(fp, &list, NULL, 3600); + if (argc > 1) + fclose(fp); + if (r) + { + fprintf(stderr, "getdns_fp2rr_list: %d\n", r); + return r; + } + + size_t len; + r = getdns_list_get_length(list, &len); + assert(!r); + for (int i = 0; i < len; i++) + { + getdns_dict *rr = NULL; + r = getdns_list_get_dict(list, i , &rr); + assert(!r); + uint8_t *buf = NULL; + size_t buf_len; + r = getdns_rr_dict2wire(rr, &buf, &buf_len); + assert(!r); + ssize_t n = write(1, buf, buf_len); + assert(n == buf_len); + } + return 0; +} -- cgit v1.1