diff --git a/modules/pico_dns_common.c b/modules/pico_dns_common.c index ed35b4eba..853d5d92c 100644 --- a/modules/pico_dns_common.c +++ b/modules/pico_dns_common.c @@ -1397,7 +1397,6 @@ pico_dns_url_get_reverse_len( const char *url, /* **************************************************************************** * Returns the qname with [url] in DNS-format, with reverse resolving - * f.e.: www.google.com => 3www6google3com0 * ****************************************************************************/ static char * pico_dns_url_to_reverse_qname( const char *url, uint8_t proto ) @@ -1419,8 +1418,8 @@ pico_dns_url_to_reverse_qname( const char *url, uint8_t proto ) memcpy(reverse_qname + (uint16_t)(strlen(url) + 2u) - 1, PICO_ARPA_IPV4_SUFFIX, strlen(PICO_ARPA_IPV4_SUFFIX)); - /* If reverse IPv6 address resolving, convert to IPv6 arpa-format */ } + /* If reverse IPv6 address resolving, convert to IPv6 arpa-format */ #ifdef PICO_SUPPORT_IPV6 else if (proto == PICO_PROTO_IPV6) { pico_dns_ipv6_set_ptr(url, reverse_qname + 1u); @@ -1432,7 +1431,8 @@ pico_dns_url_to_reverse_qname( const char *url, uint8_t proto ) else { /* If you call this function you want a reverse qname */ } - pico_dns_name_to_dns_notation(reverse_qname, strlen(url) + 2u); + reverse_qname[0] = '.'; + pico_dns_name_to_dns_notation(reverse_qname, strlen(reverse_qname) + 1); return reverse_qname; } @@ -1503,7 +1503,8 @@ pico_dns_url_to_qname( const char *url ) strcpy(qname + 1, url); /* Change to DNS notation */ - pico_dns_name_to_dns_notation(qname, strlen(url)); + qname[0] = '.'; + pico_dns_name_to_dns_notation(qname, strlen(qname) + 1); return qname; } diff --git a/test/unit/modunit_pico_dns_common.c b/test/unit/modunit_pico_dns_common.c index f3f350ca8..e369b4a7f 100644 --- a/test/unit/modunit_pico_dns_common.c +++ b/test/unit/modunit_pico_dns_common.c @@ -1115,7 +1115,7 @@ START_TEST(tc_pico_dns_url_to_reverse_qname) qname = pico_dns_url_to_reverse_qname(url_ipv4, PICO_PROTO_IPV4); fail_unless(qname != NULL, "dns_url_to_reverse_qname returned NULL!\n"); fail_unless(strcmp(qname, cmp_buf1) == 0, - "dns_url_to_reverse_qname failed with IPv4!\n"); + "dns_url_to_reverse_qname failed with IPv4 %s!\n", qname); PICO_FREE(qname); /* Try to reverse IPv6 URL */ @@ -1199,7 +1199,7 @@ START_TEST(tc_pico_dns_name_to_dns_notation) char qname1[13] = { 0x07, 'p','i','c','o','t','c','p', 0x03, 'c','o','m', 0x00 }; - char url1[13] = { 0x00,'p','i','c','o','t','c','p','.','c','o','m',0x00 }; + char url1[13] = { '.','p','i','c','o','t','c','p','.','c','o','m',0x00 }; int ret = 0; ret = pico_dns_name_to_dns_notation(url1, strlen(url1) + 2);