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

Unified Diff: net/socket/stream_listen_socket.cc

Issue 181063006: Gets the peer address (if available) in server requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated commit message, minor CR fix. Created 6 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 | « net/socket/stream_listen_socket.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/stream_listen_socket.cc
diff --git a/net/socket/stream_listen_socket.cc b/net/socket/stream_listen_socket.cc
index 960991b7c6da0be28862155cccf74cea0e56ffb6..e5232afdf8a7af6d7b57661efd8382426c217b97 100644
--- a/net/socket/stream_listen_socket.cc
+++ b/net/socket/stream_listen_socket.cc
@@ -100,6 +100,23 @@ int StreamListenSocket::GetLocalAddress(IPEndPoint* address) {
return OK;
}
+int StreamListenSocket::GetPeerAddress(IPEndPoint* address) {
+ SockaddrStorage storage;
+ if (getpeername(socket_, storage.addr, &storage.addr_len)) {
+#if defined(OS_WIN)
+ int err = WSAGetLastError();
+#else
+ int err = errno;
+#endif
+ return MapSystemError(err);
+ }
+
+ if (!address->FromSockAddr(storage.addr, storage.addr_len))
+ return ERR_ADDRESS_INVALID;
+
+ return OK;
+}
+
SocketDescriptor StreamListenSocket::AcceptSocket() {
SocketDescriptor conn = HANDLE_EINTR(accept(socket_, NULL, NULL));
if (conn == kInvalidSocket)
« no previous file with comments | « net/socket/stream_listen_socket.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698