Skip to content

Commit

Permalink
[DNS Common] - New dns_name_to_dns_notation() needed a '.' in beginni…
Browse files Browse the repository at this point in the history
…ng of URL, so added it before converting.
  • Loading branch information
jelledevleeschouwer committed May 22, 2015
1 parent c01dddc commit 0e970e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions modules/pico_dns_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/modunit_pico_dns_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0e970e2

Please sign in to comment.