Merge branch 'next' of gitorious.org:fg/simgear into next

This commit is contained in:
Stuart Buchanan
2011-08-26 19:09:51 +01:00
+24 -8
View File
@@ -115,17 +115,33 @@ void IPAddress::set ( const char* host, int port )
return; return;
} }
struct addrinfo* result = NULL; struct addrinfo hints;
int err = getaddrinfo(host, NULL, NULL /* no hints */, &result); memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET;
struct addrinfo* result0 = NULL;
int err = getaddrinfo(host, NULL, &hints, &result0);
if (err) { if (err) {
SG_LOG(SG_IO, SG_WARN, "getaddrinfo failed for '" << host << "' : " << gai_strerror(err)); SG_LOG(SG_IO, SG_WARN, "getaddrinfo failed for '" << host << "' : " << gai_strerror(err));
} else if (result->ai_addrlen != getAddrLen()) {
SG_LOG(SG_IO, SG_ALERT, "mismatch in socket address sizes");
} else { } else {
memcpy(addr, result->ai_addr, result->ai_addrlen); struct addrinfo* result;
} for (result = result0; result != NULL; result = result->ai_next) {
if (result->ai_family != AF_INET) { // only accept IP4 for the moment
freeaddrinfo(result); continue;
}
if (result->ai_addrlen != getAddrLen()) {
SG_LOG(SG_IO, SG_ALERT, "mismatch in socket address sizes: got " <<
result->ai_addrlen << ", expected " << getAddrLen());
continue;
}
memcpy(addr, result->ai_addr, result->ai_addrlen);
break;
} // of getaddrinfo results iteration
} // of getaddrinfo succeeded
freeaddrinfo(result0);
addr->sin_port = htons (port); // fix up port after getaddrinfo addr->sin_port = htons (port); // fix up port after getaddrinfo
} }