summaryrefslogtreecommitdiff
path: root/iface.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2016-04-29 10:25:38 +0200
committerTobias Klauser <tklauser@distanz.ch>2016-04-29 10:25:38 +0200
commit668d66c4e1f79081d1096c7cf63e807637b88237 (patch)
treec2b20f472a044d493244578d94085ac423ac1e21 /iface.c
parentb8bbf5de3594de63b241bf45acdc03ab4bb7eb8d (diff)
iface: Use getnameinfo() to get address from struct sockaddr_storage
Use getnameinfo() instead of inet_ntop() with weird (and incorrect) pointer arithmetics to get the numeric address from a struct sockaddr_storage. This addresses CID 99692 & 99696 discovered by the Coverity scanner. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'iface.c')
-rw-r--r--iface.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/iface.c b/iface.c
index 8c77c61..b069532 100644
--- a/iface.c
+++ b/iface.c
@@ -18,6 +18,7 @@
#include <assert.h>
#include <errno.h>
+#include <netdb.h>
#include <pthread.h>
#include <stdint.h>
#include <string.h>
@@ -143,8 +144,10 @@ static void iface_record_addr_del(struct iface_record *rec, struct sockaddr_stor
rec->addrs = addrs;
rec->size--;
} else {
- char as[INET6_ADDRSTRLEN];
- inet_ntop(addr->ss_family, addr + sizeof(addr->ss_family), as, sizeof(as));
+ char as[NI_MAXHOST];
+ if (getnameinfo((struct sockaddr *)addr, sizeof(*addr),
+ as, sizeof(as), NULL, 0, NI_NUMERICHOST))
+ strncpy(as, "<unknown>", sizeof(as) - 1);
log_err("Address %s to delete not found in records\n", as);
}
} else if (rec->size == 1) {