From 9a2987874fd118737e9242fac63fe8ba224fb683 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 24 Aug 2016 20:33:06 +0200 Subject: [PATCH 04/12] mdns_parse_response: add return code Signed-off-by: Martin Wilck --- protocol/discovery/mdns.c | 8 +++++++- protocol/discovery/mdns.h | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/protocol/discovery/mdns.c b/protocol/discovery/mdns.c index 6250d41..6670464 100644 --- a/protocol/discovery/mdns.c +++ b/protocol/discovery/mdns.c @@ -339,7 +339,7 @@ static void mdns_read_header(char *Response, DNS_PKT_HEADER *h) } -static void mdns_parse_respponse(unsigned char *Response, DNS_RECORD *rr) +static int mdns_parse_respponse(unsigned char *Response, DNS_RECORD *rr) { unsigned char *p = Response; unsigned short type = 0, data_len = 0; @@ -350,6 +350,11 @@ static void mdns_parse_respponse(unsigned char *Response, DNS_RECORD *rr) mdns_read_header(Response, &h); p += MDNS_HEADER_SIZE; + if (h.answers + h.additionals <= 0) { + DBG("mdns_parse_respponse: no answers"); + return MDNS_STATUS_ERROR; + } + for (i = 0; i < h.questions; i++) { p += mdns_readName(Response, p, rr->name); @@ -382,6 +387,7 @@ static void mdns_parse_respponse(unsigned char *Response, DNS_RECORD *rr) } DBG("mdns_parse_respponse returning MDL = %s, IP = %s\n",rr->mdl, rr->ip); + return MDNS_STATUS_OK; } static int mdns_read_single_response(int udp_socket, char *recvbuffer, int recvbufsize) diff --git a/protocol/discovery/mdns.h b/protocol/discovery/mdns.h index 96e6597..7936e1e 100644 --- a/protocol/discovery/mdns.h +++ b/protocol/discovery/mdns.h @@ -98,7 +98,7 @@ static int mdns_readName(unsigned char* start, unsigned char *p, char *buf); static int mdns_update_uris(DNS_RECORD *rr, char* uris_buf, int buf_size, int *count); static void mdns_create_query_packet(char* fqdn, int query_type, char* dnsquery, int *length); static void mdns_read_header(char *Response, DNS_PKT_HEADER *h); -static void mdns_parse_respponse(unsigned char *Response, DNS_RECORD *rr); +static int mdns_parse_respponse(unsigned char *Response, DNS_RECORD *rr, int bytes_read); static void mdns_rr_cleanup(DNS_RECORD *rr); static DNS_RECORD *mdns_read_responses(int udp_socket, int mode); static unsigned char* mdns_readMDL(unsigned char *p, unsigned char *normalized_mdl, int len); -- 2.9.2