Chromium Code Reviews| Index: runtime/bin/socket_win.cc |
| diff --git a/runtime/bin/socket_win.cc b/runtime/bin/socket_win.cc |
| index d581b8b07e81359912d47c6e593b01e63ccba49c..c566c27026a54d6a3bd877d55f0a85b8cef7ec3c 100644 |
| --- a/runtime/bin/socket_win.cc |
| +++ b/runtime/bin/socket_win.cc |
| @@ -61,14 +61,19 @@ 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)); |
| - return false; |
| - } |
| *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()); |
|
Mads Ager (google)
2012/05/21 13:24:34
Return false?
Søren Gjesse
2012/05/21 13:28:57
Good catch, thanks.
|
| + } |
| return true; |
| } |