/*
* ldnssec-utils
*
* Written in 2021 by Lucas
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software. If not, see
* .
*/
#include
#include
#include
#include
#include
#include "util.h"
static void
usage(void)
{
fprintf(stderr, "usage: %s [-f zone]\n", getprogname());
exit(1);
}
int
main(int argc, char *argv[])
{
ldns_zone *zone;
ldns_status s;
FILE *fp;
char *filename;
int ch, line_nr;
fp = NULL;
filename = NULL;
while ((ch = getopt(argc, argv, "f:")) != -1) {
switch (ch) {
case 'f':
if (fp != NULL)
errx(1, "-f can be used only once");
filename = optarg;
fp = fopen(filename, "r");
if (fp == NULL)
err(1, "fopen");
break;
default:
usage();
}
}
argc -= optind;
argv += optind;
if (fp == NULL) {
filename = "(stdin)";
fp = stdin;
}
fatal_check_minimum_ldns_revision();
s = ldns_zone_new_frm_fp_l(&zone, fp, NULL, LDNS_DEFAULT_TTL,
LDNS_RR_CLASS_IN, &line_nr);
if (s != LDNS_STATUS_OK)
errx(1, "ldns_zone_new_frm_fp_l: file %s line %d: %s",
filename, line_nr, ldns_get_errorstr_by_id(s));
if (fp != stdin)
(void)fclose(fp);
ldns_zone_print(stdout, zone);
ldns_zone_deep_free(zone);
return 0;
}