Skip to content

Commit

Permalink
Merge pull request openucx#5 from dmitrygx/topic/fix_sockaddr
Browse files Browse the repository at this point in the history
UCS/UCP/UCT/TEST: Replace sockaddr by sockaddr_storage
  • Loading branch information
yosefe authored Apr 27, 2020
2 parents bf4eb87 + d3ae6e4 commit 7012795
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions test/apps/iodemo/ucx_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,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 "<unknown address family>";
}

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 "<invalid address>";
}

snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ":%d", port);
return buf;
}

Expand Down

0 comments on commit 7012795

Please sign in to comment.