From c821cdcbe4ce05bab0a44455ed94e3886332506c Mon Sep 17 00:00:00 2001 From: Darell Tan Date: Wed, 17 Oct 2012 21:31:36 +0800 Subject: [PATCH] Added more debugging statements. --- mdns.c | 13 +++++++++++++ mdns.h | 2 ++ mdnsd.c | 8 +++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/mdns.c b/mdns.c index cfdd501..26f1496 100644 --- a/mdns.c +++ b/mdns.c @@ -246,6 +246,19 @@ static uint8_t *uncompress_nlabel(uint8_t *pkt_buf, size_t pkt_len, size_t off) // ----- RR list & group functions ----- +const char *rr_get_type_name(enum rr_type type) { + switch (type) { + case RR_A: return "A"; + case RR_PTR: return "PTR"; + case RR_TXT: return "TXT"; + case RR_AAAA: return "AAAA"; + case RR_SRV: return "SRV"; + case RR_NSEC: return "NSEC"; + case RR_ANY: return "ANY"; + } + return NULL; +} + void rr_entry_destroy(struct rr_entry *rr) { struct rr_data_txt *txt_rec; assert(rr); diff --git a/mdns.h b/mdns.h index 332d721..bf28c72 100644 --- a/mdns.h +++ b/mdns.h @@ -173,6 +173,8 @@ struct rr_entry *rr_create(uint8_t *name, enum rr_type type); void rr_set_nsec(struct rr_entry *rr_nsec, enum rr_type type); void rr_add_txt(struct rr_entry *rr_txt, const char *txt); +const char *rr_get_type_name(enum rr_type type); + uint8_t *create_label(const char *txt); uint8_t *create_nlabel(const char *name); char *nlabel_to_str(const uint8_t *name); diff --git a/mdnsd.c b/mdnsd.c index 37ead2b..58e9617 100644 --- a/mdnsd.c +++ b/mdnsd.c @@ -261,7 +261,7 @@ static int process_mdns_pkt(struct mdnsd *svr, struct mdns_pkt *pkt, struct mdns int num_ans_added = 0; char *namestr = nlabel_to_str(qn->name); - DEBUG_PRINTF("qn #%d: type 0x%02x %s - ", i, qn->type, namestr); + DEBUG_PRINTF("qn #%d: type %s (%02x) %s - ", i, rr_get_type_name(qn->type), qn->type, namestr); free(namestr); // check if it's a unicast query - we ignore those @@ -282,6 +282,10 @@ static int process_mdns_pkt(struct mdnsd *svr, struct mdns_pkt *pkt, struct mdns struct rr_list *next_ans = ans->next; if (rr_entry_match(pkt->rr_ans, ans->e)) { + char *namestr = nlabel_to_str(ans->e->name); + DEBUG_PRINTF("removing answer for %s\n", namestr); + free(namestr); + // check if list item is head if (prev_ans == NULL) reply->rr_ans = ans->next; @@ -354,6 +358,8 @@ static void main_loop(struct mdnsd *svr) { if (process_mdns_pkt(svr, mdns, mdns_reply)) { size_t replylen = mdns_encode_pkt(mdns_reply, pkt_buffer, PACKET_SIZE); send_packet(svr->sockfd, pkt_buffer, replylen); + } else if (mdns->num_qn == 0) { + DEBUG_PRINTF("(no questions in packet)\n\n"); } mdns_pkt_destroy(mdns);