From 93211cc99ad39909436d2d67e732fb4cd6fc6fcb Mon Sep 17 00:00:00 2001 From: Neel Goyal Date: Thu, 12 Dec 2013 13:59:53 -0500 Subject: [PATCH] Fix for issue #43 - add additional header fields --- src/types-internal.h | 21 ++++++++++++++++++--- src/util-internal.c | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/types-internal.h b/src/types-internal.h index ecb22a61..893dfb8d 100644 --- a/src/types-internal.h +++ b/src/types-internal.h @@ -63,9 +63,6 @@ struct getdns_context; #define GETDNS_STR_KEY_HEADER "header" #define GETDNS_STR_KEY_QUESTION "question" #define GETDNS_STR_KEY_ANSWER "answer" -#define GETDNS_STR_KEY_ID "id" -#define GETDNS_STR_KEY_QR "qr" -#define GETDNS_STR_KEY_OPC "opcode" #define GETDNS_STR_KEY_TYPE "type" #define GETDNS_STR_KEY_CLASS "class" #define GETDNS_STR_KEY_TTL "ttl" @@ -78,6 +75,24 @@ struct getdns_context; #define GETDNS_STR_KEY_QTYPE "qtype" #define GETDNS_STR_KEY_QCLASS "qclass" #define GETDNS_STR_KEY_QNAME "qname" +#define GETDNS_STR_KEY_QR "qr" +/* header flags */ +#define GETDNS_STR_KEY_ID "id" +#define GETDNS_STR_KEY_OPCODE "opcode" +#define GETDNS_STR_KEY_RCODE "rcode" +#define GETDNS_STR_KEY_AA "aa" +#define GETDNS_STR_KEY_TC "tc" +#define GETDNS_STR_KEY_RD "rd" +#define GETDNS_STR_KEY_RA "ra" +#define GETDNS_STR_KEY_AD "ad" +#define GETDNS_STR_KEY_CD "cd" +#define GETDNS_STR_KEY_Z "z" +#define GETDNS_STR_KEY_QDCOUNT "qdcount" +#define GETDNS_STR_KEY_ANCOUNT "ancount" +#define GETDNS_STR_KEY_NSCOUNT "nscount" +#define GETDNS_STR_KEY_ARCOUNT "arcount" + + /** @} */ diff --git a/src/util-internal.c b/src/util-internal.c index d6a44943..69ab46d4 100644 --- a/src/util-internal.c +++ b/src/util-internal.c @@ -184,10 +184,41 @@ create_reply_header_dict(struct getdns_context *context, ldns_pkt * reply) /* cheat since we know GETDNS_RETURN_GOOD == 0 */ r |= getdns_dict_set_int(result, GETDNS_STR_KEY_ID, ldns_pkt_id(reply)); - r |= getdns_dict_set_int(result, GETDNS_STR_KEY_QR, - ldns_pkt_qr(reply)); - r |= getdns_dict_set_int(result, GETDNS_STR_KEY_OPC, - (int) ldns_pkt_get_opcode(reply)); + + /* set bits - seems like this could be macro-ified*/ + r |= getdns_dict_set_int(result, GETDNS_STR_KEY_QR, + (int) ldns_pkt_qr(reply)); + r |= getdns_dict_set_int(result, GETDNS_STR_KEY_AA, + (int) ldns_pkt_aa(reply)); + r |= getdns_dict_set_int(result, GETDNS_STR_KEY_TC, + (int) ldns_pkt_tc(reply)); + r |= getdns_dict_set_int(result, GETDNS_STR_KEY_RD, + (int) ldns_pkt_rd(reply)); + r |= getdns_dict_set_int(result, GETDNS_STR_KEY_CD, + (int) ldns_pkt_cd(reply)); + r |= getdns_dict_set_int(result, GETDNS_STR_KEY_RA, + (int) ldns_pkt_aa(reply)); + r |= getdns_dict_set_int(result, GETDNS_STR_KEY_AD, + (int) ldns_pkt_ad(reply)); + + /* codes */ + r |= getdns_dict_set_int(result, GETDNS_STR_KEY_OPCODE, + (int) ldns_pkt_get_opcode(reply)); + r |= getdns_dict_set_int(result, GETDNS_STR_KEY_RCODE, + (int) ldns_pkt_get_rcode(reply)); + /* default z to 0 */ + r |= getdns_dict_set_int(result, GETDNS_STR_KEY_Z, 0); + + /* counts */ + r |= getdns_dict_set_int(result, GETDNS_STR_KEY_QDCOUNT, + (int) ldns_pkt_qdcount(reply)); + r |= getdns_dict_set_int(result, GETDNS_STR_KEY_ANCOUNT, + (int) ldns_pkt_ancount(reply)); + r |= getdns_dict_set_int(result, GETDNS_STR_KEY_NSCOUNT, + (int) ldns_pkt_nscount(reply)); + r |= getdns_dict_set_int(result, GETDNS_STR_KEY_ARCOUNT, + (int) ldns_pkt_arcount(reply)); + if (r != 0) { getdns_dict_destroy(result);