Skip to content

Commit 9164e26

Browse files
committed
Provide the correct socklen to bind.
Get Brian's patch from #5825 and his log message: Fix a failure in binding the initiating side of a connection on MacOS. MacOS doesn't like passing the size of the storage structure (sockaddr_storage) instead of the expected size of the structure (sockaddr_in or sockaddr_in6), which was causing bind() failures. This patch simply changes the structure size to the expected size. Add a more clear error message in debug mode. Signed-off-by: George Bosilca <bosilca@icl.utk.edu>
1 parent fcc1d30 commit 9164e26

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

opal/mca/btl/tcp/btl_tcp_endpoint.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -728,34 +728,39 @@ static int mca_btl_tcp_endpoint_start_connect(mca_btl_base_endpoint_t* btl_endpo
728728

729729
/* start the connect - will likely fail with EINPROGRESS */
730730
mca_btl_tcp_proc_tosocks(btl_endpoint->endpoint_addr, &endpoint_addr);
731-
731+
732732
/* Bind the socket to one of the addresses associated with
733733
* this btl module. This sets the source IP to one of the
734734
* addresses shared in modex, so that the destination rank
735735
* can properly pair btl modules, even in cases where Linux
736736
* might do something unexpected with routing */
737-
opal_socklen_t sockaddr_addrlen = sizeof(struct sockaddr_storage);
738737
if (endpoint_addr.ss_family == AF_INET) {
739738
assert(NULL != &btl_endpoint->endpoint_btl->tcp_ifaddr);
740739
if (bind(btl_endpoint->endpoint_sd, (struct sockaddr*) &btl_endpoint->endpoint_btl->tcp_ifaddr,
741-
sockaddr_addrlen) < 0) {
742-
BTL_ERROR(("bind() failed: %s (%d)", strerror(opal_socket_errno), opal_socket_errno));
740+
sizeof(struct sockaddr_in)) < 0) {
741+
BTL_ERROR(("bind on local address (%s:%d) failed: %s (%d)",
742+
opal_net_get_hostname((struct sockaddr*) &btl_endpoint->endpoint_btl->tcp_ifaddr),
743+
htons(((struct sockaddr_in*)&btl_endpoint->endpoint_btl->tcp_ifaddr)->sin_port),
744+
strerror(opal_socket_errno), opal_socket_errno));
743745

744-
CLOSE_THE_SOCKET(btl_endpoint->endpoint_sd);
745-
return OPAL_ERROR;
746-
}
746+
CLOSE_THE_SOCKET(btl_endpoint->endpoint_sd);
747+
return OPAL_ERROR;
748+
}
747749
}
748750
#if OPAL_ENABLE_IPV6
749751
if (endpoint_addr.ss_family == AF_INET6) {
750752
assert(NULL != &btl_endpoint->endpoint_btl->tcp_ifaddr_6);
751753
if (bind(btl_endpoint->endpoint_sd, (struct sockaddr*) &btl_endpoint->endpoint_btl->tcp_ifaddr_6,
752-
sockaddr_addrlen) < 0) {
753-
BTL_ERROR(("bind() failed: %s (%d)", strerror(opal_socket_errno), opal_socket_errno));
754+
sizeof(struct sockaddr_in6)) < 0) {
755+
BTL_ERROR(("bind on local address (%s:%d) failed: %s (%d)",
756+
opal_net_get_hostname((struct sockaddr*) &btl_endpoint->endpoint_btl->tcp_ifaddr),
757+
htons(((struct sockaddr_in*)&btl_endpoint->endpoint_btl->tcp_ifaddr)->sin_port),
758+
strerror(opal_socket_errno), opal_socket_errno));
754759

755-
CLOSE_THE_SOCKET(btl_endpoint->endpoint_sd);
756-
return OPAL_ERROR;
757-
}
758-
}
760+
CLOSE_THE_SOCKET(btl_endpoint->endpoint_sd);
761+
return OPAL_ERROR;
762+
}
763+
}
759764
#endif
760765
opal_output_verbose(10, opal_btl_base_framework.framework_output,
761766
"btl: tcp: attempting to connect() to %s address %s on port %d",

0 commit comments

Comments
 (0)