Better handling of inet_ntop() failures (which should not happen in practice, since we filter on address family, but let's be cautious).

This commit is contained in:
Thomas Pornin 2016-11-12 15:30:47 +01:00
parent 0d974e1c9c
commit 16d0864818
2 changed files with 6 additions and 2 deletions

View file

@ -87,7 +87,9 @@ host_bind(const char *host, const char *port, int verbose)
sa_len = p->ai_addrlen;
}
if (addr != NULL) {
inet_ntop(p->ai_family, addr, tmp, sizeof tmp);
if (!inet_ntop(p->ai_family, addr, tmp, sizeof tmp)) {
strcpy(tmp, "<invalid>");
}
} else {
sprintf(tmp, "<unknown family: %d>",
(int)sa->sa_family);