From: Jelte Jansen Date: Fri, 24 Dec 2004 10:22:48 +0000 (+0000) Subject: added lookup tables for rcodes and opcodes X-Git-Tag: release-0.50~590 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=02103fc2f52906a8b75fc72ae29249d919351eec;p=thirdparty%2Fldns.git added lookup tables for rcodes and opcodes --- diff --git a/host2str.c b/host2str.c index c6c69a32..9163d2ca 100644 --- a/host2str.c +++ b/host2str.c @@ -47,7 +47,7 @@ ldns_lookup_table ldns_algorithms[] = { { 0, NULL } }; -/* rr types (TODO: maybe these should be in rr.c? */ +/* rr types (TODO: maybe these should be in rr.c? add enum? */ ldns_lookup_table ldns_rr_classes[] = { { LDNS_RR_CLASS_IN, "IN" }, { LDNS_RR_CLASS_CHAOS, "CH" }, @@ -56,6 +56,24 @@ ldns_lookup_table ldns_rr_classes[] = { { 0, NULL } }; +/* if these are used elsewhere, move to packet.c? */ +ldns_lookup_table ldns_rcodes[] = { + { 0, "NOERROR" }, + { 1, "FORMERR" }, + { 2, "SERVFAIL" }, + { 3, "NAMEERR" }, + { 4, "NOTIMPL" }, + { 5, "REFUSED" }, + { 0, NULL } +}; + +ldns_lookup_table ldns_opcodes[] = { + { 0, "QUERY" }, + { 1, "IQUERY" }, + { 2, "STATUS" }, + { 0, NULL } +}; + /* this is temp function for debugging wire2rr */ /* do NOT pass compressed data here :p */ ldns_status @@ -310,8 +328,14 @@ ldns_pktheader2buffer(ldns_buffer *output, ldns_pkt *pkt) /* TODO: strings for known names instead of numbers, flags etc */ if ( ldns_buffer_printf(output, ";; ->>HEADER<<- ") < 0 || - ldns_buffer_printf(output, "opcode: %u, ", ldns_pkt_opcode(pkt)) < 0 || - ldns_buffer_printf(output, "status: %u, ", ldns_pkt_rcode(pkt)) < 0 || + ldns_buffer_printf(output, "opcode: %s, ", + ldns_lookup_by_id(ldns_opcodes, + (int) ldns_pkt_opcode(pkt))->name + ) < 0 || + ldns_buffer_printf(output, "status: %s, ", + ldns_lookup_by_id(ldns_rcodes, + (int) ldns_pkt_rcode(pkt))->name + ) < 0 || ldns_buffer_printf(output, "id %lu\n", ldns_pkt_id(pkt)) < 0 || ldns_buffer_printf(output, ";; flags: ") < 0 ) diff --git a/run-test1.c b/run-test1.c index c40dfb84..59b73ec5 100644 --- a/run-test1.c +++ b/run-test1.c @@ -44,7 +44,7 @@ doit(void) printf("_short: ah man, shit hit the fan\n"); } - ldns_rdf2buffer_int16(buf, rdata); + (void) ldns_rdf2buffer_int16(buf, rdata); fprintf(stderr, "%s\n", buffer2str(buf)); } diff --git a/util.c b/util.c index b103717b..6cb5b493 100644 --- a/util.c +++ b/util.c @@ -57,6 +57,7 @@ ldns_lookup_table * ldns_lookup_by_id(ldns_lookup_table *table, int id) { while (table->name != NULL) { +printf("trying %s with id %d (%d)\n", table->name, table->id, id); if (table->id == id) return table; table++;