Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Unified Diff: runtime/bin/socket_win.cc

Issue 9624005: Fix hostname lookup on Windows (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor fixes Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/standalone/src/io/HttpClientTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_win.cc
diff --git a/runtime/bin/socket_win.cc b/runtime/bin/socket_win.cc
index dc5dec803671259c58e29ff9fbf1b793918916c1..4dfbe4aa7b779621037f39204be3daf3cecae7da 100644
--- a/runtime/bin/socket_win.cc
+++ b/runtime/bin/socket_win.cc
@@ -73,20 +73,29 @@ intptr_t Socket::CreateConnect(const char* host, const intptr_t port) {
FATAL("Failed setting SO_LINGER on socket");
}
- struct hostent* server = gethostbyname(host);
- if (server == NULL) {
- fprintf(stderr, "Error CreateConnect: %d\n", WSAGetLastError());
- closesocket(s);
+ // Perform a name lookup for an IPv4 address.
+ struct addrinfo hints;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
+ struct addrinfo* result = NULL;
+ status = getaddrinfo(host, 0, &hints, &result);
+ if (status != NO_ERROR) {
+ fprintf(stderr, "getaddrinfo failed with error: %d\n", status);
return -1;
}
+ // Copy IPv4 address and set the port.
struct sockaddr_in server_address;
- server_address.sin_family = AF_INET;
+ memcpy(&server_address,
+ reinterpret_cast<sockaddr_in *>(result->ai_addr),
+ sizeof(server_address));
server_address.sin_port = htons(port);
- server_address.sin_addr.s_addr = inet_addr(host);
+ freeaddrinfo(result); // Free data allocated by getaddrinfo.
status = connect(
s,
- reinterpret_cast<struct sockaddr *>(&server_address),
+ reinterpret_cast<struct sockaddr*>(&server_address),
sizeof(server_address));
if (status == SOCKET_ERROR) {
fprintf(stderr, "Error CreateConnect: %d\n", WSAGetLastError());
« no previous file with comments | « no previous file | tests/standalone/src/io/HttpClientTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698