From: Jelte Jansen Date: Mon, 20 Dec 2004 14:23:07 +0000 (+0000) Subject: enum for packet sections X-Git-Tag: release-0.50~635 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aba123d38e465f697a737343eba49b810459b13a;p=thirdparty%2Fldns.git enum for packet sections --- diff --git a/ldns/packet.h b/ldns/packet.h index 03d1a1cb..12d5da77 100644 --- a/ldns/packet.h +++ b/ldns/packet.h @@ -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 *); diff --git a/ldns/wire2host.h b/ldns/wire2host.h index 5e76d6f3..751a860e 100644 --- a/ldns/wire2host.h +++ b/ldns/wire2host.h @@ -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 diff --git a/wire2host.c b/wire2host.c index f5b294af..6fc1cca2 100644 --- a/wire2host.c +++ b/wire2host.c @@ -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); }