From: Miek Gieben Date: Tue, 12 Apr 2005 13:43:11 +0000 (+0000) Subject: another nice program from the master X-Git-Tag: release-0.50~138 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4fc772ee0dd36344b8119bd63a39bb3344efc97;p=thirdparty%2Fldns.git another nice program from the master --- diff --git a/Makefile.in b/Makefile.in index 727e9da3..72576426 100644 --- a/Makefile.in +++ b/Makefile.in @@ -45,7 +45,7 @@ LIBDNS_HEADERS = ldns/error.h \ ldns/higher.h \ ldns/parse.h \ util.h -PROG_SOURCES = mx.c +PROG_SOURCES = mx.c chaos.c PROG_TARGETS = $(PROG_SOURCES:.c=) LIBDNS_OBJECTS = $(LIBDNS_SOURCES:.c=.o) @@ -84,6 +84,9 @@ snapshot: clean testclean mx: mx.o $(LIBDNS_OBJECTS) $(LIBOBJS) $(LINK) ${LIBS} -o $@ $+ +chaos: chaos.o $(LIBDNS_OBJECTS) $(LIBOBJS) + $(LINK) ${LIBS} -o $@ $+ + # tests run-test7: run-test7.o $(LIBDNS_OBJECTS) $(LIBOBJS) diff --git a/chaos.c b/chaos.c new file mode 100644 index 00000000..582c49e0 --- /dev/null +++ b/chaos.c @@ -0,0 +1,96 @@ +/* + * soa is a small programs that prints out the soa record + * for a particulary domain + */ + +#include +#include +#include + +int +usage(FILE *fp, char *prog) { + fprintf(fp, "%s server\n", prog); + fprintf(fp, " print out some information about server\n"); + return 0; +} + +int +main(int argc, char *argv[]) +{ + ldns_resolver *res; + ldns_rdf *name; + ldns_rdf *version, *id; + ldns_pkt *p; + ldns_rr_list *addr; + ldns_rr_list *info; + size_t i; + + if (argc != 2) { + usage(stdout, argv[0]); + exit(1); + } else { + /* create a rdf from the command line arg */ + name = ldns_dname_new_frm_str(argv[1]); + if (!name) { + usage(stdout, argv[0]); + exit(1); + } + } + + version = ldns_dname_new_frm_str("version.bind"); + id = ldns_dname_new_frm_str("hostname.bind"); + + /* create a new resolver from /etc/resolv.conf */ + res = ldns_resolver_new_frm_file(NULL); + if (!res) { + exit(1); + } + + /* use the resolver to send it a query for the a/aaaa of name */ + addr = ldns_get_rr_list_addr_by_name(res, name, LDNS_RR_CLASS_IN, LDNS_RD); + if (!addr) { + fprintf(stderr, " *** could not get an address for %s", argv[1]); + exit(1); + } + /* remove old nameservers */ + while(!ldns_resolver_pop_nameserver(res)) { ; } + + /* can be multihomed */ + for(i = 0; i < ldns_rr_list_rr_count(addr); i++) { + ldns_resolver_push_nameserver_rr(res, + ldns_rr_list_rr(addr, i)); + + ldns_rr_print(stdout, ldns_rr_list_rr(addr, i)); + fprintf(stdout, "\n"); + + p = ldns_resolver_query(res, version, LDNS_RR_TYPE_TXT, + LDNS_RR_CLASS_CH, LDNS_RD); + if (p) { + info = ldns_pkt_rr_list_by_type(p, + LDNS_RR_TYPE_TXT, LDNS_SECTION_ANSWER); + + ldns_rr_list_print(stdout, info); + } else { + printf(" *** query failed for %s\n", + ldns_rr2str(ldns_rr_list_rr(addr, i))); + ldns_pkt_free(p); + } + + p = ldns_resolver_query(res, id, LDNS_RR_TYPE_TXT, + LDNS_RR_CLASS_CH, LDNS_RD); + if (p) { + info = ldns_pkt_rr_list_by_type(p, + LDNS_RR_TYPE_TXT, LDNS_SECTION_ANSWER); + ldns_rr_list_print(stdout, info); + } else { + printf(" *** query failed for %s\n", + ldns_rr2str(ldns_rr_list_rr(addr, i))); + } + (void)ldns_resolver_pop_nameserver(res); + fprintf(stdout, "\n"); + + } + exit(0); + + return 0; +} diff --git a/host2str.c b/host2str.c index 857d450b..b12adc24 100644 --- a/host2str.c +++ b/host2str.c @@ -54,7 +54,7 @@ ldns_lookup_table ldns_algorithms[] = { /* classes */ ldns_lookup_table ldns_rr_classes[] = { { LDNS_RR_CLASS_IN, "IN" }, - { LDNS_RR_CLASS_CHAOS, "CH" }, + { LDNS_RR_CLASS_CH, "CH" }, { LDNS_RR_CLASS_HS, "HS" }, { LDNS_RR_CLASS_ANY, "ANY" }, { 0, NULL } diff --git a/ldns/rr.h b/ldns/rr.h index ff336467..e2ca9aac 100644 --- a/ldns/rr.h +++ b/ldns/rr.h @@ -38,7 +38,7 @@ enum ldns_enum_rr_class /** the Internet */ LDNS_RR_CLASS_IN = 1, /** Chaos class */ - LDNS_RR_CLASS_CHAOS = 3, + LDNS_RR_CLASS_CH = 3, /** Hesiod (Dyer 87) */ LDNS_RR_CLASS_HS = 4, /** Any class */ diff --git a/libdns.vim b/libdns.vim index ff481a23..4e7c261e 100644 --- a/libdns.vim +++ b/libdns.vim @@ -105,7 +105,7 @@ syn keyword ldnsType ldns_rr_class syn keyword ldnsType ldns_rr_compress syn keyword ldnsConstant LDNS_RR_CLASS_IN -syn keyword ldnsConstant LDNS_RR_CLASS_CHAOS +syn keyword ldnsConstant LDNS_RR_CLASS_CH syn keyword ldnsConstant LDNS_RR_CLASS_HS syn keyword ldnsConstant LDNS_RR_CLASS_ANY diff --git a/resolver.c b/resolver.c index dbd71a7a..1fb4b8cd 100644 --- a/resolver.c +++ b/resolver.c @@ -720,6 +720,7 @@ ldns_resolver_send(ldns_resolver *r, ldns_rdf *name, ldns_rr_type type, ldns_rr_ printf("Failed to generate pkt\n"); return NULL; } + /* transfer the udp_edns_size from the resolver to the packet */ if (ldns_resolver_edns_udp_size(r) != 0) { ldns_pkt_set_edns_udp_size(query_pkt, @@ -762,7 +763,6 @@ dprintf("RESALGO: %s\n", ldns_resolver_tsig_algorithm(r)); return NULL; } } - /* return NULL on error */ for (retries = ldns_resolver_retry(r); retries > 0; retries--) { answer_pkt = ldns_send(r, query_pkt); diff --git a/util.h b/util.h index 00a6bcc1..703d5eb0 100644 --- a/util.h +++ b/util.h @@ -15,8 +15,8 @@ #include -#define dprintf(X,Y) printf((X), (Y)) -/* #define dprintf(X, Y) */ +/* #define dprintf(X,Y) printf((X), (Y)) */ +#define dprintf(X, Y) /** * splint static inline workaround