static const char *addrpair(const PgAddr *src, const PgAddr *dst)
{
- static char ip1buf[INET6_ADDRSTRLEN], ip2buf[INET6_ADDRSTRLEN],
- buf[INET6_ADDRSTRLEN+INET6_ADDRSTRLEN+128];
+ static char ip1buf[PGADDR_BUF], ip2buf[PGADDR_BUF],
+ buf[2*PGADDR_BUF + 16];
const char *ip1, *ip2;
if (pga_is_unix(src))
return "unix->unix";
ip1 = pga_ntop(src, ip1buf, sizeof(ip1buf));
- if (!ip1)
- ip1 = strerror(errno);
ip2 = pga_ntop(src, ip2buf, sizeof(ip2buf));
- if (!ip2)
- ip2 = strerror(errno);
snprintf(buf, sizeof(buf), "%s:%d -> %s:%d",
ip1, pga_port(src), ip2, pga_port(dst));
return buf;
if (pga_is_unix(&sock->remote_addr)) {
host = "unix";
} else {
- memset(host6, 0, sizeof(host6));
host = pga_ntop(&sock->remote_addr, host6, sizeof(host6));
- if (!host)
- host = "(ntop-err)";
}
port = pga_port(&sock->remote_addr);
/* convert pgaddr to string */
const char *pga_ntop(const PgAddr *a, char *dst, int dstlen)
{
+ const char *res = NULL;
+ char buf[PGADDR_BUF];
+
+ memset(buf, 0, sizeof(buf));
+
switch (pga_family(a)) {
case AF_UNIX:
- strlcpy(dst, "unix", dstlen);
- return dst;
+ res = "unix";
+ break;
case AF_INET:
- return inet_ntop(AF_INET, &a->sin.sin_addr, dst, dstlen);
+ res = inet_ntop(AF_INET, &a->sin.sin_addr, buf, sizeof(buf));
+ break;
case AF_INET6:
- return inet_ntop(AF_INET6, &a->sin6.sin6_addr, dst, dstlen);
+ res = inet_ntop(AF_INET6, &a->sin6.sin6_addr, buf, sizeof(buf));
+ break;
default:
- return NULL;
+ res = "(bad-af)";
}
+ if (res == NULL)
+ res = "(err-ntop)";
+
+ strlcpy(dst, res, dstlen);
+ return dst;
}
/* parse address from string */
const char *pga_str(const PgAddr *a, char *dst, int dstlen)
{
char buf[PGADDR_BUF];
- if (!pga_ntop(a, buf, sizeof(buf)))
- return NULL;
+ pga_ntop(a, buf, sizeof(buf));
snprintf(dst, dstlen, "%s@%d", buf, pga_port(a));
return dst;
}