diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2016-04-29 10:25:38 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2016-04-29 10:25:38 +0200 |
commit | 668d66c4e1f79081d1096c7cf63e807637b88237 (patch) | |
tree | c2b20f472a044d493244578d94085ac423ac1e21 /iface.c | |
parent | b8bbf5de3594de63b241bf45acdc03ab4bb7eb8d (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.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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) { |