[MINOR] make use of addr_to_str() and get_host_port() to replace many inet_ntop()
Many inet_ntop calls were partially right, which was hard to detect given
the complex combinations. Some of them were relying on the listener's proto
instead of the address itself, which could have been different when dealing
with an accept-proxy connection.
The new addr_to_str() function does the dirty job and returns the family, which
makes it particularly suited to calls from switch/case statements. A large number
of if/else statements were removed and the stats output could even be cleaned up
in the case of session dump.
As a side effect of doing this, the resulting code is smaller by almost 1kB.
All changed parts have been tested and provided expected output.
diff --git a/src/log.c b/src/log.c
index 16ace2f..d750349 100644
--- a/src/log.c
+++ b/src/log.c
@@ -317,15 +317,7 @@
if (!err && (fe->options2 & PR_O2_NOLOGNORM))
return;
- if (s->si[0].addr.c.from.ss_family == AF_INET)
- inet_ntop(AF_INET,
- (const void *)&((struct sockaddr_in *)&s->si[0].addr.c.from)->sin_addr,
- pn, sizeof(pn));
- else if (s->si[0].addr.c.from.ss_family == AF_INET6)
- inet_ntop(AF_INET6,
- (const void *)&((struct sockaddr_in6 *)(&s->si[0].addr.c.from))->sin6_addr,
- pn, sizeof(pn));
-
+ addr_to_str(&s->si[0].addr.c.from, pn, sizeof(pn));
get_localtime(s->logs.tv_accept.tv_sec, &tm);
if (fe->logfac1 < 0 && fe->logfac2 < 0)