Acked-by: Christian Babeux <christian.babeux@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
*/
#define _GNU_SOURCE
+#include <assert.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdlib.h>
unsigned char buf[sizeof(struct in6_addr)];
struct hostent *record;
+ assert(addr);
+ assert(dst);
+
+ memset(dst, 0, size);
+
/* Network protocol */
ret = inet_pton(af, addr, buf);
if (ret < 1) {
/* Translate IP to string */
(void) inet_ntop(af, record->h_addr_list[0], dst, size);
} else {
- memcpy(dst, addr, size);
+ if (size > 0) {
+ strncpy(dst, addr, size);
+ dst[size - 1] = '\0';
+ }
}
DBG2("IP address resolved to %s", dst);