]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
enum for packet sections
authorJelte Jansen <jeltejan@NLnetLabs.nl>
Mon, 20 Dec 2004 14:23:07 +0000 (14:23 +0000)
committerJelte Jansen <jeltejan@NLnetLabs.nl>
Mon, 20 Dec 2004 14:23:07 +0000 (14:23 +0000)
ldns/packet.h
ldns/wire2host.h
wire2host.c

index 03d1a1cb7292d2cde5ab2fbb171a22a3bb821795..12d5da77e333c66c2ec4d878a8bbe4c5f9f13bcb 100644 (file)
@@ -75,6 +75,17 @@ struct ldns_struct_pkt
 };
 typedef struct ldns_struct_pkt ldns_pkt;
 
+/**
+ * The sections of a packet
+ */
+enum ldns_enum_pkt_section {
+       LDNS_SECTION_QUESTION = 0,
+       LDNS_SECTION_ANSWER = 1,
+       LDNS_SECTION_AUTHORITY = 2,
+       LDNS_SECTION_ADDITIONAL = 3
+};
+typedef enum ldns_enum_pkt_section ldns_pkt_section;   
+
 /* prototypes */
 uint16_t pkt_id(ldns_pkt *);
 bool pkt_qr(ldns_pkt *);
index 5e76d6f3a58cac77b705d1f46ccafd159c1825e7..751a860e33bd4ea9eb94b4129e1fbeff3b986e1f 100644 (file)
@@ -22,7 +22,7 @@ ldns_status ldns_wire2pkt(ldns_pkt **packet, const uint8_t *data, size_t len);
 ldns_status ldns_wire2dname(ldns_rdf **dname, const uint8_t *wire, size_t max, 
                        size_t *pos);
 ldns_status ldns_wire2rr(ldns_rr **rr, const uint8_t *wire, size_t max,
-                    size_t *pos, int section);
+                    size_t *pos, ldns_pkt_section section);
 
 #endif
 
index f5b294af847291cf30b8130deca2b1c031fa0776..6fc1cca25aa384f8697a67559c774047a2716a53 100644 (file)
@@ -422,13 +422,12 @@ ldns_wire2rdf(ldns_rr *rr, const uint8_t *wire,
 
 
 /* TODO:
-         enum for sections? 
          can *pos be incremented at READ_INT? or maybe use something like
          RR_CLASS(wire)?
 */
 ldns_status
 ldns_wire2rr(ldns_rr **rr_p, const uint8_t *wire, size_t max, 
-             size_t *pos, int section)
+             size_t *pos, ldns_pkt_section section)
 {
        ldns_rdf *owner;
        ldns_rr *rr = ldns_rr_new();
@@ -445,7 +444,7 @@ ldns_wire2rr(ldns_rr **rr_p, const uint8_t *wire, size_t max,
        ldns_rr_set_class(rr, read_uint16(&wire[*pos]));
        *pos = *pos + 2;
 
-       if (section > 0) {
+       if (section != LDNS_SECTION_QUESTION) {
                ldns_rr_set_ttl(rr, read_uint32(&wire[*pos]));  
                *pos = *pos + 4;
                status = ldns_wire2rdf(rr, wire, max, pos);
@@ -506,19 +505,23 @@ ldns_wire2pkt(ldns_pkt **packet_p, const uint8_t *wire, size_t max)
        
        /* TODO: section enum :) */
        for (i = 0; i < pkt_qdcount(packet); i++) {
-               status = ldns_wire2rr(&rr, wire, max, &pos, 0);
+               status = ldns_wire2rr(&rr, wire, max, &pos,
+                                     LDNS_SECTION_QUESTION);
                STATUS_CHECK_GOTO(status, status_error);
        }
        for (i = 0; i < pkt_ancount(packet); i++) {
-               status = ldns_wire2rr(&rr, wire, max, &pos, 1);
+               status = ldns_wire2rr(&rr, wire, max, &pos,
+                                     LDNS_SECTION_ANSWER);
                STATUS_CHECK_GOTO(status, status_error);
        }
        for (i = 0; i < pkt_nscount(packet); i++) {
-               status = ldns_wire2rr(&rr, wire, max, &pos, 2);
+               status = ldns_wire2rr(&rr, wire, max, &pos,
+                                     LDNS_SECTION_AUTHORITY);
                STATUS_CHECK_GOTO(status, status_error);
        }
        for (i = 0; i < pkt_arcount(packet); i++) {
-               status = ldns_wire2rr(&rr, wire, max, &pos, 3);
+               status = ldns_wire2rr(&rr, wire, max, &pos,
+                                     LDNS_SECTION_ADDITIONAL);
                STATUS_CHECK_GOTO(status, status_error);
        }