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

Unified Diff: runtime/bin/socket_linux.cc

Issue 10032027: Add remoteHost to Socket. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Removed then need for allocating buffer in heap. 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
« no previous file with comments | « runtime/bin/socket_impl.dart ('k') | runtime/bin/socket_macos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_linux.cc
diff --git a/runtime/bin/socket_linux.cc b/runtime/bin/socket_linux.cc
index 57772ae13cb14974f969ae71f751c998d0fa2413..e3507df67f85f9a0e14742df0111d9ba4d8712e9 100644
--- a/runtime/bin/socket_linux.cc
+++ b/runtime/bin/socket_linux.cc
@@ -102,7 +102,8 @@ intptr_t Socket::GetPort(intptr_t fd) {
}
-intptr_t Socket::GetRemotePort(intptr_t fd) {
+bool Socket::GetRemotePeer(intptr_t fd, char *host, intptr_t *port) {
+ ASSERT(DART_INET_ADDRSTRLEN >= INET_ADDRSTRLEN);
ASSERT(fd >= 0);
struct sockaddr_in socket_address;
socklen_t size = sizeof(socket_address);
@@ -111,9 +112,17 @@ 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 false;
}
- return ntohs(socket_address.sin_port);
+ if (inet_ntop(socket_address.sin_family,
+ reinterpret_cast<const 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);
+ return true;
}
« no previous file with comments | « runtime/bin/socket_impl.dart ('k') | runtime/bin/socket_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698