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

Unified Diff: runtime/bin/socket_win.cc

Issue 10032027: Add remoteHost to Socket. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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
« runtime/bin/socket.cc ('K') | « runtime/bin/socket_macos.cc ('k') | no next file » | 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 fc48ecfe3eb00872e78f6b32536a72ababe4cca0..e5930d12a2a5f8d4fd38382501abc1d16c86e68f 100644
--- a/runtime/bin/socket_win.cc
+++ b/runtime/bin/socket_win.cc
@@ -54,7 +54,7 @@ intptr_t Socket::GetPort(intptr_t fd) {
}
-intptr_t Socket::GetRemotePort(intptr_t fd) {
+bool Socket::GetRemotePeer(intptr_t fd, const char **host, intptr_t *port) {
ASSERT(reinterpret_cast<Handle*>(fd)->is_socket());
SocketHandle* socket_handle = reinterpret_cast<SocketHandle*>(fd);
struct sockaddr_in socket_address;
@@ -63,10 +63,20 @@ intptr_t Socket::GetRemotePort(intptr_t fd) {
reinterpret_cast<struct sockaddr *>(&socket_address),
&size)) {
fprintf(stderr, "Error getpeername: %s\n", strerror(errno));
- return 0;
- }
- return ntohs(socket_address.sin_port);
-}
+ return false;
+ }
+ char* buffer = new char[INET_ADDRSTRLEN];
+ if (inet_ntop(socket_address.sin_family,
+ reinterpret_cast<const void *>(&socket_address.sin_addr),
+ buffer,
+ INET_ADDRSTRLEN) == NULL) {
+ fprintf(stderr, "Error inet_ntop: %s\n", strerror(errno));
+ delete[] buffer;
+ return false;
+ }
+ *host = buffer;
+ *port = ntohs(socket_address.sin_port);
+ return true;
intptr_t Socket::CreateConnect(const char* host, const intptr_t port) {
« runtime/bin/socket.cc ('K') | « runtime/bin/socket_macos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698