Date: Wednesday, December 20, 2006 @ 21:40:54
Author: gilles
Path: /cvsroot/carob/carob/src
Modified: ControllerInfo.cpp (1.9 -> 1.10)
Tentative partial fix for CAROB-117: try to get non zero address if any (for
ControllerInfo UDP address)
--------------------+
ControllerInfo.cpp | 43 +++++++++++++++++++++++++++++++++++++------
1 files changed, 37 insertions(+), 6 deletions(-)
Index: carob/src/ControllerInfo.cpp
diff -u carob/src/ControllerInfo.cpp:1.9 carob/src/ControllerInfo.cpp:1.10
--- carob/src/ControllerInfo.cpp:1.9 Wed Dec 20 19:38:41 2006
+++ carob/src/ControllerInfo.cpp Wed Dec 20 21:40:54 2006
@@ -45,17 +45,48 @@
original_hostname(name), UDP_addr_len(0), has_been_connected(false),
TCP_sock_addr_len(0)
{
-
// get the udp addresses
struct addrinfo* addrs = getAddrs(name, port, SOCK_DGRAM, AF_UNSPEC); //
AF_UNSPEC = all families, function return will tell us which
// UDP_addrs always contain at least one address, otherwise an exception
would
// have been thrown
- // we cannot know for sure which of the returned addresses is valid. Consider
- // that the first one is ok and discard others
+ // We cannot know for sure which of the returned addresses is valid, so we
+ // take the first one, preferably the one which sin_addr is not 0, and
discard
+ // others
UDP_addr_len = addrs->ai_addrlen;
-// UDP_addr = *(addrs->ai_addr);
- memcpy(&UDP_addr, addrs->ai_addr, UDP_addr_len);
- // discards the previous addresses
+ // Try to find an address with non 0 sin_addr
+ struct addrinfo* iter = addrs;
+ bool nonZeroAddrFound = false;
+ while (!nonZeroAddrFound && iter != NULL)
+ {
+ if (iter->ai_addr->sa_family == AF_INET)
+ {
+ sockaddr_in inAddr;
+ memcpy(&inAddr, &(iter->ai_addr), iter->ai_addrlen);
+ if (inAddr.sin_addr.s_addr != 0)
+ nonZeroAddrFound = true;
+ }
+ else if (iter->ai_addr->sa_family == AF_INET6)
+ {
+ sockaddr_in6 inAddr6;
+ memcpy(&inAddr6, &(iter->ai_addr), iter->ai_addrlen);
+ for (int i = 0; i < 16; i++)
+ {
+ if (inAddr6.sin6_addr.s6_addr[i] != 0)
+ {
+ nonZeroAddrFound = true;
+ break;
+ }
+ }
+ }
+ if (!nonZeroAddrFound) // keep the position of the good address
+ iter = iter->ai_next;
+ }
+ if (!nonZeroAddrFound)
+ // not found, let's use the first one
+ iter = addrs;
+
+ memcpy(&UDP_addr, iter->ai_addr, UDP_addr_len);
+ // discards the returned addresses
freeaddrinfo(addrs);
// get the unique numeric host name from this UDP address
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits