};
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 *);
/* 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();
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);
/* 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);
}