]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
added lookup tables for rcodes and opcodes
authorJelte Jansen <jeltejan@NLnetLabs.nl>
Fri, 24 Dec 2004 10:22:48 +0000 (10:22 +0000)
committerJelte Jansen <jeltejan@NLnetLabs.nl>
Fri, 24 Dec 2004 10:22:48 +0000 (10:22 +0000)
host2str.c
run-test1.c
util.c

index c6c69a32889e506b1bce4225bdaa2cc8c70c6323..9163d2cae514f5c456ebe4e833faa552e3a78146 100644 (file)
@@ -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
           )
index c40dfb8479bd9f998f0f900ca70aade8db8dfed9..59b73ec53e5057268a2c7bbc058bfe299c18c3c2 100644 (file)
@@ -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 b103717be6a6140a3716b711464042fde742344c..6cb5b493cca23dae395ef7608dac214a0ea4414f 100644 (file)
--- 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++;