summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiek Gieben <miekg@NLnetLabs.nl>2006-04-06 11:47:17 +0200
committerMiek Gieben <miekg@NLnetLabs.nl>2006-04-06 11:47:17 +0200
commiteaaeceecb924298033c22289d86a3cd18392ac13 (patch)
tree916f8948d0f52189bc6f2550e597ad350a90fd18
parent5fe7c246306cccce957c720c1cff648f4d834cfc (diff)
downloadldns-eaaeceecb924298033c22289d86a3cd18392ac13.tar.gz
only check z not *z when assigning in zone.c
keyfetch: use ldns_zone_new_frm_fp_l
-rw-r--r--examples/ldns-keyfetcher.c54
-rw-r--r--zone.c3
2 files changed, 16 insertions, 41 deletions
diff --git a/examples/ldns-keyfetcher.c b/examples/ldns-keyfetcher.c
index ff17e471..2a668a2d 100644
--- a/examples/ldns-keyfetcher.c
+++ b/examples/ldns-keyfetcher.c
@@ -8,15 +8,12 @@
*/
#include "config.h"
-
#include <ldns/dns.h>
-
#include <errno.h>
int verbosity = 0;
-
-int
+void
usage(FILE *fp, char *prog) {
fprintf(fp, "%s domain\n", prog);
fprintf(fp, " retrieve out the dnskeys for domain\n");
@@ -24,7 +21,6 @@ usage(FILE *fp, char *prog) {
fprintf(fp, "-h\t\tShow this help\n");
fprintf(fp, "-r <file>\tUse file to read root hints from\n");
fprintf(fp, "-v <int>\tVerbosity level (0-5, not verbose-very verbose)\n");
- return 0;
}
ldns_rr_list *
@@ -46,7 +42,6 @@ retrieve_dnskeys(ldns_resolver *local_res, ldns_rdf *name, ldns_rr_type t,
size_t nss_i;
ldns_rr_list *answer_list = NULL;
ldns_rr_list *authority_list = NULL;
-/* ldns_rr_list *additional_list = NULL;*/
size_t last_nameserver_count;
ldns_rdf **last_nameservers;
@@ -288,7 +283,6 @@ retrieve_dnskeys(ldns_resolver *local_res, ldns_rdf *name, ldns_rr_type t,
}
-
ldns_rr_list_deep_free(answer_list);
answer_list = NULL;
/* clone the nameserver list, we are going to handle them one by one */
@@ -317,7 +311,7 @@ retrieve_dnskeys(ldns_resolver *local_res, ldns_rdf *name, ldns_rr_type t,
status = ldns_resolver_send(&p, res, name, t, c, 0);
if (!p) {
- printf("no p\n");
+ fprintf(stderr, "no packet received\n");
return NULL;
}
@@ -375,9 +369,8 @@ ldns_rr_list *
read_root_hints(const char *filename)
{
FILE *fp = NULL;
- ldns_rr_list *dns_root = NULL;
- ldns_rr *rr;
int line_nr = 0;
+ ldns_zone *z;
ldns_status status;
fp = fopen(filename, "r");
@@ -386,37 +379,14 @@ read_root_hints(const char *filename)
return NULL;
}
- dns_root = ldns_rr_list_new();
-
- /* TODO: Check NS records etc. */
- while (!feof(fp)) {
- /* like zone_new_frm_fp, but no directives for ttl, origin, etc. */
- rr = NULL;
- status = ldns_rr_new_frm_fp_l(&rr, fp, NULL, NULL, NULL, &line_nr);
-
- if (status == LDNS_STATUS_OK && rr) {
- if (ldns_rr_get_type(rr) == LDNS_RR_TYPE_A) {
- ldns_rr_list_push_rr(dns_root, rr);
- } else {
- ldns_rr_free(rr);
- }
- } else {
- if (rr) {
- printf("ERROR BUT RR!\n");
- }
- /* extra check for eof, we get syntax error if last line was comment */
- if (feof(fp)) {
- ldns_rr_free(rr);
- } else {
- fprintf(stderr, "Error reading root hints (line %d): %s\n", line_nr, ldns_get_errorstr_by_id(status));
- exit(EXIT_FAILURE);
- }
- }
- }
-
+ status = ldns_zone_new_frm_fp_l(&z, fp, NULL, 0, 0, &line_nr);
fclose(fp);
-
- return dns_root;
+ if (status != LDNS_STATUS_OK) {
+ fprintf(stderr, "error\n");
+ return NULL;
+ } else {
+ return ldns_zone_rrs(z);
+ }
}
@@ -476,6 +446,10 @@ main(int argc, char *argv[])
}
dns_root = read_root_hints(root_file);
+ if (!dns_root) {
+ fprintf(stderr, "cannot read the root hints file\n");
+ exit(EXIT_FAILURE);
+ }
/* create a new resolver from /etc/resolv.conf */
status = ldns_resolver_new_frm_file(&res, NULL);
diff --git a/zone.c b/zone.c
index c032023a..8131a45a 100644
--- a/zone.c
+++ b/zone.c
@@ -210,6 +210,7 @@ ldns_zone_new_frm_fp_l(ldns_zone **z, FILE *fp, ldns_rdf *origin, uint16_t ttl,
my_ttl = ldns_rr_ttl(rr);
my_class = ldns_rr_get_class(rr);
case LDNS_STATUS_SYNTAX_EMPTY:
+ /* empty line was seen */
case LDNS_STATUS_SYNTAX_TTL:
/* the function set the ttl */
break;
@@ -221,7 +222,7 @@ ldns_zone_new_frm_fp_l(ldns_zone **z, FILE *fp, ldns_rdf *origin, uint16_t ttl,
if (my_origin) {
ldns_rdf_deep_free(my_origin);
}
- if (z && *z) {
+ if (z) {
*z = newzone;
}
return LDNS_STATUS_OK;