From: Jelte Jansen Date: Mon, 31 Jan 2005 12:58:52 +0000 (+0000) Subject: convenience print functions X-Git-Tag: release-0.50~502 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=62620a277aba2d9a4382c00dc4e8498873bd4aef;p=thirdparty%2Fldns.git convenience print functions --- diff --git a/host2str.c b/host2str.c index 7f7919bd..6d39737e 100644 --- a/host2str.c +++ b/host2str.c @@ -886,3 +886,37 @@ ldns_pkt2str(ldns_pkt *pkt) ldns_buffer_free(tmp_buffer); return result; } + +void +ldns_rdf_print(FILE *output, ldns_rdf *rdf) +{ + char *str = ldns_rdf2str(rdf); + if (str) { + fprintf(output, str); + } else { + fprintf(output, "Unable to convert rdf to string\n"); + } +} + +void +ldns_rr_print(FILE *output, ldns_rr *rr) +{ + char *str = ldns_rr2str(rr); + if (str) { + fprintf(output, str); + } else { + fprintf(output, "Unable to convert rr to string\n"); + } +} + +void +ldns_pkt_print(FILE *output, ldns_pkt *pkt) +{ + char *str = ldns_pkt2str(pkt); + if (str) { + fprintf(output, str); + } else { + fprintf(output, "Unable to convert packet to string\n"); + } +} + diff --git a/ldns/host2str.h b/ldns/host2str.h index c5667989..1e278ffb 100644 --- a/ldns/host2str.h +++ b/ldns/host2str.h @@ -20,6 +20,8 @@ char *ldns_rdf2str(ldns_rdf *); char *ldns_rr2str(ldns_rr *); char *ldns_pkt2str(ldns_pkt *); char *buffer2str(ldns_buffer *); - +void ldns_rdf_print(FILE *output, ldns_rdf *rdf); +void ldns_rr_print(FILE *output, ldns_rr *rr); +void ldns_pkt_print(FILE *output, ldns_pkt *pkt); #endif diff --git a/run-test5.c b/run-test5.c index 31ba2c45..84a72427 100644 --- a/run-test5.c +++ b/run-test5.c @@ -2,10 +2,9 @@ #include int -main(int argc, char **argv) +main() { ldns_pkt *packet; - char *str; printf("test 5\n"); @@ -13,9 +12,8 @@ main(int argc, char **argv) LDNS_RR_TYPE_A, LDNS_RR_CLASS_IN); - str = ldns_pkt2str(packet); - - printf("packet:\n%s\n\n", str); + printf("Packet:\n"); + ldns_pkt_print(stdout, packet); return 0;