From d3ae6e4e3bb0fe8548df17a57481b68906c6982f Mon Sep 17 00:00:00 2001 From: dmitrygx Date: Mon, 27 Apr 2020 18:57:17 +0300 Subject: [PATCH] TEST/APPS: Use sokcaddr_storage instead of sockaddr in IO demo --- test/apps/iodemo/ucx_wrapper.cc | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/test/apps/iodemo/ucx_wrapper.cc b/test/apps/iodemo/ucx_wrapper.cc index 0fc6af89834..26324e0a67c 100644 --- a/test/apps/iodemo/ucx_wrapper.cc +++ b/test/apps/iodemo/ucx_wrapper.cc @@ -217,16 +217,30 @@ const std::string UcxContext::sockaddr_str(const struct sockaddr* saddr, size_t addrlen) { char buf[128]; + int port; if (saddr->sa_family != AF_INET) { return ""; } - struct sockaddr_in in_addr = {0}; - memcpy(&in_addr, saddr, addrlen); - inet_ntop(AF_INET, &in_addr.sin_addr, buf, sizeof(buf)); - snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ":%d", - ntohs(in_addr.sin_port)); + struct sockaddr_storage addr = {0}; + memcpy(&addr, saddr, addrlen); + switch (addr.ss_family) { + case AF_INET: + inet_ntop(AF_INET, &((struct sockaddr_in*)&addr)->sin_addr, + buf, sizeof(buf)); + port = ntohs(((struct sockaddr_in*)&addr)->sin_port); + break; + case AF_INET6: + inet_ntop(AF_INET, &((struct sockaddr_in6*)&addr)->sin6_addr, + buf, sizeof(buf)); + port = ntohs(((struct sockaddr_in6*)&addr)->sin6_port); + break; + default: + return ""; + } + + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ":%d", port); return buf; }