Skip to content

Commit dfc2d72

Browse files
authored
Merge pull request #5824 from jsquyres/pr/v3.0.x/fix-tcp-btl-show-help-ip-address
v3.0.x: btl/tcp: output the IP address correctly
2 parents d15a3e9 + 2f86f72 commit dfc2d72

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

opal/mca/btl/tcp/btl_tcp_proc.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -835,24 +835,22 @@ void mca_btl_tcp_proc_accept(mca_btl_tcp_proc_t* btl_proc, struct sockaddr* addr
835835
/* No further use of this socket. Close it */
836836
CLOSE_THE_SOCKET(sd);
837837
{
838-
char *addr_str=NULL, *tmp, pnet[1024];
838+
char *addr_str = NULL, *tmp;
839+
char ip[128];
840+
ip[sizeof(ip) - 1] = '\0';
841+
839842
for (size_t i = 0; i < btl_proc->proc_endpoint_count; i++) {
840843
mca_btl_base_endpoint_t* btl_endpoint = btl_proc->proc_endpoints[i];
841844
if (btl_endpoint->endpoint_addr->addr_family != addr->sa_family) {
842845
continue;
843846
}
844-
if (AF_INET == addr->sa_family) {
845-
inet_ntop(AF_INET, (void*)(struct in_addr*)&btl_endpoint->endpoint_addr->addr_inet, pnet, 1024);
846-
} else if (AF_INET6 == addr->sa_family) {
847-
inet_ntop(AF_INET6, (void*)(struct in6_addr*)&btl_endpoint->endpoint_addr->addr_inet, pnet, 1024);
848-
} else {
849-
/* unrecognized family */
850-
continue;
851-
}
847+
inet_ntop(btl_endpoint->endpoint_addr->addr_family,
848+
(void*) &(btl_endpoint->endpoint_addr->addr_inet),
849+
ip, sizeof(ip) - 1);
852850
if (NULL == addr_str) {
853-
(void)asprintf(&tmp, "\n\t%s", pnet);
851+
(void)asprintf(&tmp, "\n\t%s", ip);
854852
} else {
855-
(void)asprintf(&tmp, "%s\n\t%s", addr_str, pnet);
853+
(void)asprintf(&tmp, "%s\n\t%s", addr_str, ip);
856854
free(addr_str);
857855
}
858856
addr_str = tmp;

0 commit comments

Comments
 (0)