Chromium Code Reviews| Index: runtime/bin/socket_win.cc |
| diff --git a/runtime/bin/socket_win.cc b/runtime/bin/socket_win.cc |
| index 4dfbe4aa7b779621037f39204be3daf3cecae7da..1bcddba3a744302e09297e09d434079d1ea8b26e 100644 |
| --- a/runtime/bin/socket_win.cc |
| +++ b/runtime/bin/socket_win.cc |
| @@ -144,6 +144,40 @@ intptr_t ServerSocket::Accept(intptr_t fd) { |
| } |
| +const char* Socket::LookupIPv4Address(char* host, OSError** os_error) { |
| + // 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* info = NULL; |
| + int status = getaddrinfo(host, 0, &hints, &info); |
| + if (status != 0) { |
| + ASSERT(*os_error == NULL); |
| + *os_error = new OSError(status, |
| + gai_strerror(status), |
| + OSError::kGetAddressInfo); |
| + (*os_error)->set_code(status); |
| + (*os_error)->SetMessage(gai_strerror(status)); |
| + return NULL; |
| + } |
| + // Convert the address into IPv4 dotted decomal notation. |
|
Mads Ager (google)
2012/03/14 12:51:51
Ditto.
Søren Gjesse
2012/03/19 10:05:43
Done.
|
| + char* buffer = reinterpret_cast<char*>(malloc(INET_ADDRSTRLEN)); |
| + sockaddr_in *sockaddr = reinterpret_cast<sockaddr_in *>(info->ai_addr); |
| + const char* result = inet_ntop(AF_INET, |
| + reinterpret_cast<void *>(&sockaddr->sin_addr), |
| + buffer, |
| + INET_ADDRSTRLEN); |
| + if (result == NULL) { |
| + free(buffer); |
| + return NULL; |
| + } |
| + ASSERT(result == buffer); |
| + return buffer; |
| +} |
| + |
| + |
| intptr_t ServerSocket::CreateBindListen(const char* host, |
| intptr_t port, |
| intptr_t backlog) { |