From 97a293e46ab051bb7da811ba4763cb50d3557d42 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Fri, 21 Aug 2020 14:43:10 +0200 Subject: stream: Fix log of IPv6 during accept() Change-Id: Ib13db8d135138059a70d18a8bba14e53c6514fa7 --- src/stream.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/stream.c b/src/stream.c index e265ee1..5f171ea 100644 --- a/src/stream.c +++ b/src/stream.c @@ -834,7 +834,9 @@ static int osmo_stream_srv_fd_cb(struct osmo_fd *ofd, unsigned int what) { int ret; int sock_fd; - struct sockaddr_in sa; + char addrstr[128]; + bool is_ipv6; + struct sockaddr_storage sa; socklen_t sa_len = sizeof(sa); struct osmo_stream_srv_link *link = ofd->data; @@ -844,8 +846,13 @@ static int osmo_stream_srv_fd_cb(struct osmo_fd *ofd, unsigned int what) "peer, reason=`%s'\n", strerror(errno)); return ret; } + is_ipv6 = ((struct sockaddr *)&sa)->sa_family == AF_INET6; LOGP(DLINP, LOGL_DEBUG, "accept()ed new link from %s to port %u\n", - inet_ntoa(sa.sin_addr), link->port); + inet_ntop(is_ipv6 ? AF_INET6 : AF_INET, + is_ipv6 ? (void*)&(((struct sockaddr_in6 *)&sa)->sin6_addr) : + (void*)&(((struct sockaddr_in *)&sa)->sin_addr), + addrstr, sizeof(addrstr)), + link->port); sock_fd = ret; if (link->proto == IPPROTO_SCTP) { -- cgit v1.2.3