Make standalone Dart VM run on Windows XP

Use the function WSAAddressToString for converting an IP address to a string
instead of inet_ntop. WSAAddressToString is available on Windows XP.

R=ager@google.com

BUG=dart:2559
TEST=tests\standalone\io\socket_info_test.dart

Review URL: https://chromiumcodereview.appspot.com//10409051

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@7797 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
sgjesse@google.com
2012-05-21 13:31:01 +00:00
parent 61b9b899a3
commit 2571ceeca8
+12 -6
View File
@@ -61,14 +61,20 @@ bool Socket::GetRemotePeer(intptr_t fd, char *host, intptr_t *port) {
fprintf(stderr, "Error getpeername: %s\n", strerror(errno));
return false;
}
if (inet_ntop(socket_address.sin_family,
reinterpret_cast<void *>(&socket_address.sin_addr),
host,
INET_ADDRSTRLEN) == NULL) {
fprintf(stderr, "Error inet_ntop: %s\n", strerror(errno));
*port = ntohs(socket_address.sin_port);
// Clear the port before calling WSAAddressToString as WSAAddressToString
// includes the port in the formatted string.
socket_address.sin_port = 0;
DWORD len = INET_ADDRSTRLEN;
int err = WSAAddressToString(reinterpret_cast<LPSOCKADDR>(&socket_address),
sizeof(socket_address),
NULL,
host,
&len);
if (err != 0) {
fprintf(stderr, "Error WSAAddressToString: %d\n", WSAGetLastError());
return false;
}
*port = ntohs(socket_address.sin_port);
return true;
}