coap_debug.c: Improve len parameter handling for inet_ntop()

Commit 32e219a has resolved an issue with the size parameter for
inet_ntop() in a way that introduces errors on certain Linux
platforms. This change now passes the exact size for AF_INET
and AF_INET6 to fix that.
This commit is contained in:
Olaf Bergmann committed 2019-05-09 14:09:41 +02:00
1 parent a5f434e685
commit 552fc37cde
1 file changed
+4 -1
+4 -1
View File
@@ -174,11 +174,13 @@ coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t le
const void *addrptr = NULL;
in_port_t port;
unsigned char *p = buf;
size_t need_buf;
switch (addr->addr.sa.sa_family) {
case AF_INET:
addrptr = &addr->addr.sin.sin_addr;
port = ntohs(addr->addr.sin.sin_port);
need_buf = INET_ADDRSTRLEN;
break;
case AF_INET6:
if (len < 7) /* do not proceed if buffer is even too short for [::]:0 */
@@ -188,6 +190,7 @@ coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t le
addrptr = &addr->addr.sin6.sin6_addr;
port = ntohs(addr->addr.sin6.sin6_port);
need_buf = INET6_ADDRSTRLEN;
break;
default:
@@ -197,7 +200,7 @@ coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t le
/* Cast needed for Windows, since it doesn't have the correct API signature. */
if (inet_ntop(addr->addr.sa.sa_family, addrptr, (char *)p,
min(len, addr->size)) == 0) {
min(len, need_buf)) == 0) {
perror("coap_print_addr");
return 0;
}