summaryrefslogtreecommitdiff
path: root/tools/dnssec/dns-text2wire.c
blob: 99d418f011eb59c66029bda67b818e885d246207 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
  Read RR's in zone file format and write them in wire format.
*/

#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <getdns/getdns.h>
#include <getdns/getdns_extra.h>

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;
}