diff options
Diffstat (limited to 'net/socket')
22 files changed, 102 insertions, 1 deletions
diff --git a/net/socket/client_socket.h b/net/socket/client_socket.h index 358716c..f57fe3f 100644 --- a/net/socket/client_socket.h +++ b/net/socket/client_socket.h @@ -12,6 +12,7 @@ namespace net { class AddressList; +class IPEndPoint; class ClientSocket : public Socket { public: @@ -53,8 +54,13 @@ class ClientSocket : public Socket { // Copies the peer address to |address| and returns a network error code. // ERR_SOCKET_NOT_CONNECTED will be returned if the socket is not connected. + // TODO(sergeyu): Use IPEndPoint instead of AddressList. virtual int GetPeerAddress(AddressList* address) const = 0; + // Copies the local address to |address| and returns a network error code. + // ERR_SOCKET_NOT_CONNECTED will be returned if the socket is not connected. + virtual int GetLocalAddress(IPEndPoint* address) const = 0; + // Gets the NetLog for this socket. virtual const BoundNetLog& NetLog() const = 0; diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc index 8fc42c3..eb83289 100644 --- a/net/socket/client_socket_pool_base_unittest.cc +++ b/net/socket/client_socket_pool_base_unittest.cc @@ -76,6 +76,10 @@ class MockClientSocket : public ClientSocket { return ERR_UNEXPECTED; } + virtual int GetLocalAddress(IPEndPoint* /* address */) const { + return ERR_UNEXPECTED; + } + virtual const BoundNetLog& NetLog() const { return net_log_; } diff --git a/net/socket/socket_test_util.cc b/net/socket/socket_test_util.cc index 43cdf03..577c7d2 100644 --- a/net/socket/socket_test_util.cc +++ b/net/socket/socket_test_util.cc @@ -648,6 +648,14 @@ int MockClientSocket::GetPeerAddress(AddressList* address) const { 0, address, NULL); } +int MockClientSocket::GetLocalAddress(IPEndPoint* address) const { + IPAddressNumber ip; + if (!ParseIPLiteralToNumber("192.0.2.33", &ip)) + return ERR_FAILED; + *address = IPEndPoint(ip, 123); + return OK; +} + const BoundNetLog& MockClientSocket::NetLog() const { return net_log_; } diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h index 21301f7..823c3b8 100644 --- a/net/socket/socket_test_util.h +++ b/net/socket/socket_test_util.h @@ -580,6 +580,7 @@ class MockClientSocket : public net::SSLClientSocket { virtual bool IsConnected() const; virtual bool IsConnectedAndIdle() const; virtual int GetPeerAddress(AddressList* address) const; + virtual int GetLocalAddress(IPEndPoint* address) const; virtual const BoundNetLog& NetLog() const; virtual void SetSubresourceSpeculation() {} virtual void SetOmniboxSpeculation() {} diff --git a/net/socket/socks5_client_socket.cc b/net/socket/socks5_client_socket.cc index 42c8603..80b335e 100644 --- a/net/socket/socks5_client_socket.cc +++ b/net/socket/socks5_client_socket.cc @@ -483,4 +483,8 @@ int SOCKS5ClientSocket::GetPeerAddress(AddressList* address) const { return transport_->socket()->GetPeerAddress(address); } +int SOCKS5ClientSocket::GetLocalAddress(IPEndPoint* address) const { + return transport_->socket()->GetLocalAddress(address); +} + } // namespace net diff --git a/net/socket/socks5_client_socket.h b/net/socket/socks5_client_socket.h index 81804492..1981990 100644 --- a/net/socket/socks5_client_socket.h +++ b/net/socket/socks5_client_socket.h @@ -69,6 +69,7 @@ class SOCKS5ClientSocket : public ClientSocket { virtual bool SetSendBufferSize(int32 size); virtual int GetPeerAddress(AddressList* address) const; + virtual int GetLocalAddress(IPEndPoint* address) const; private: enum State { diff --git a/net/socket/socks_client_socket.cc b/net/socket/socks_client_socket.cc index a47861e..1afeaa6 100644 --- a/net/socket/socks_client_socket.cc +++ b/net/socket/socks_client_socket.cc @@ -414,4 +414,8 @@ int SOCKSClientSocket::GetPeerAddress(AddressList* address) const { return transport_->socket()->GetPeerAddress(address); } +int SOCKSClientSocket::GetLocalAddress(IPEndPoint* address) const { + return transport_->socket()->GetLocalAddress(address); +} + } // namespace net diff --git a/net/socket/socks_client_socket.h b/net/socket/socks_client_socket.h index 9d4fba9..1d2cb8d 100644 --- a/net/socket/socks_client_socket.h +++ b/net/socket/socks_client_socket.h @@ -66,6 +66,7 @@ class SOCKSClientSocket : public ClientSocket { virtual bool SetSendBufferSize(int32 size); virtual int GetPeerAddress(AddressList* address) const; + virtual int GetLocalAddress(IPEndPoint* address) const; private: FRIEND_TEST_ALL_PREFIXES(SOCKSClientSocketTest, CompleteHandshake); diff --git a/net/socket/ssl_client_socket_mac.cc b/net/socket/ssl_client_socket_mac.cc index 09103ce..9a40e45 100644 --- a/net/socket/ssl_client_socket_mac.cc +++ b/net/socket/ssl_client_socket_mac.cc @@ -618,6 +618,10 @@ int SSLClientSocketMac::GetPeerAddress(AddressList* address) const { return transport_->socket()->GetPeerAddress(address); } +int SSLClientSocketMac::GetLocalAddress(IPEndPoint* address) const { + return transport_->socket()->GetLocalAddress(address); +} + const BoundNetLog& SSLClientSocketMac::NetLog() const { return net_log_; } diff --git a/net/socket/ssl_client_socket_mac.h b/net/socket/ssl_client_socket_mac.h index 058d1a3..d465cce 100644 --- a/net/socket/ssl_client_socket_mac.h +++ b/net/socket/ssl_client_socket_mac.h @@ -51,6 +51,7 @@ class SSLClientSocketMac : public SSLClientSocket { virtual bool IsConnected() const; virtual bool IsConnectedAndIdle() const; virtual int GetPeerAddress(AddressList* address) const; + virtual int GetLocalAddress(IPEndPoint* address) const; virtual const BoundNetLog& NetLog() const; virtual void SetSubresourceSpeculation(); virtual void SetOmniboxSpeculation(); diff --git a/net/socket/ssl_client_socket_nss.cc b/net/socket/ssl_client_socket_nss.cc index a2396b1..4142acb 100644 --- a/net/socket/ssl_client_socket_nss.cc +++ b/net/socket/ssl_client_socket_nss.cc @@ -715,6 +715,10 @@ int SSLClientSocketNSS::GetPeerAddress(AddressList* address) const { return transport_->socket()->GetPeerAddress(address); } +int SSLClientSocketNSS::GetLocalAddress(IPEndPoint* address) const { + return transport_->socket()->GetLocalAddress(address); +} + const BoundNetLog& SSLClientSocketNSS::NetLog() const { return net_log_; } diff --git a/net/socket/ssl_client_socket_nss.h b/net/socket/ssl_client_socket_nss.h index 88f1f79..bbda8b9 100644 --- a/net/socket/ssl_client_socket_nss.h +++ b/net/socket/ssl_client_socket_nss.h @@ -70,6 +70,7 @@ class SSLClientSocketNSS : public SSLClientSocket { virtual bool IsConnected() const; virtual bool IsConnectedAndIdle() const; virtual int GetPeerAddress(AddressList* address) const; + virtual int GetLocalAddress(IPEndPoint* address) const; virtual const BoundNetLog& NetLog() const; virtual void SetSubresourceSpeculation(); virtual void SetOmniboxSpeculation(); diff --git a/net/socket/ssl_client_socket_openssl.cc b/net/socket/ssl_client_socket_openssl.cc index 395c067..bea8efd 100644 --- a/net/socket/ssl_client_socket_openssl.cc +++ b/net/socket/ssl_client_socket_openssl.cc @@ -1058,6 +1058,10 @@ int SSLClientSocketOpenSSL::GetPeerAddress(AddressList* addressList) const { return transport_->socket()->GetPeerAddress(addressList); } +int SSLClientSocketOpenSSL::GetLocalAddress(IPEndPoint* addressList) const { + return transport_->socket()->GetLocalAddress(addressList); +} + const BoundNetLog& SSLClientSocketOpenSSL::NetLog() const { return net_log_; } diff --git a/net/socket/ssl_client_socket_openssl.h b/net/socket/ssl_client_socket_openssl.h index c4fb8dc..82d11fb 100644 --- a/net/socket/ssl_client_socket_openssl.h +++ b/net/socket/ssl_client_socket_openssl.h @@ -63,6 +63,7 @@ class SSLClientSocketOpenSSL : public SSLClientSocket { virtual bool IsConnected() const; virtual bool IsConnectedAndIdle() const; virtual int GetPeerAddress(AddressList* address) const; + virtual int GetLocalAddress(IPEndPoint* address) const; virtual const BoundNetLog& NetLog() const; virtual void SetSubresourceSpeculation(); virtual void SetOmniboxSpeculation(); @@ -163,4 +164,3 @@ class SSLClientSocketOpenSSL : public SSLClientSocket { } // namespace net #endif // NET_SOCKET_SSL_CLIENT_SOCKET_OPENSSL_H_ - diff --git a/net/socket/ssl_client_socket_win.cc b/net/socket/ssl_client_socket_win.cc index 2ae8673..7dd5abf 100644 --- a/net/socket/ssl_client_socket_win.cc +++ b/net/socket/ssl_client_socket_win.cc @@ -695,6 +695,10 @@ int SSLClientSocketWin::GetPeerAddress(AddressList* address) const { return transport_->socket()->GetPeerAddress(address); } +int SSLClientSocketWin::GetLocalAddress(IPEndPoint* address) const { + return transport_->socket()->GetLocalAddress(address); +} + void SSLClientSocketWin::SetSubresourceSpeculation() { if (transport_.get() && transport_->socket()) { transport_->socket()->SetSubresourceSpeculation(); diff --git a/net/socket/ssl_client_socket_win.h b/net/socket/ssl_client_socket_win.h index f9a6f94..30fab5f 100644 --- a/net/socket/ssl_client_socket_win.h +++ b/net/socket/ssl_client_socket_win.h @@ -56,6 +56,7 @@ class SSLClientSocketWin : public SSLClientSocket { virtual bool IsConnected() const; virtual bool IsConnectedAndIdle() const; virtual int GetPeerAddress(AddressList* address) const; + virtual int GetLocalAddress(IPEndPoint* address) const; virtual const BoundNetLog& NetLog() const { return net_log_; } virtual void SetSubresourceSpeculation(); virtual void SetOmniboxSpeculation(); diff --git a/net/socket/ssl_server_socket_unittest.cc b/net/socket/ssl_server_socket_unittest.cc index 6269282..4ff7481 100644 --- a/net/socket/ssl_server_socket_unittest.cc +++ b/net/socket/ssl_server_socket_unittest.cc @@ -27,6 +27,7 @@ #include "net/base/cert_verifier.h" #include "net/base/host_port_pair.h" #include "net/base/io_buffer.h" +#include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" #include "net/base/net_log.h" #include "net/base/ssl_config_service.h" @@ -148,6 +149,12 @@ class FakeSocket : public ClientSocket { return net::OK; } + virtual int GetLocalAddress(IPEndPoint* address) const { + net::IPAddressNumber ip_address(4); + *address = net::IPEndPoint(ip_address, 0); + return net::OK; + } + virtual const BoundNetLog& NetLog() const { return net_log_; } diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc index 1c7cdc0..d386bae 100644 --- a/net/socket/tcp_client_socket_libevent.cc +++ b/net/socket/tcp_client_socket_libevent.cc @@ -21,6 +21,7 @@ #include "net/base/address_list_net_log_param.h" #include "net/base/connection_type_histograms.h" #include "net/base/io_buffer.h" +#include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" #include "net/base/net_log.h" #include "net/base/net_util.h" @@ -618,6 +619,23 @@ int TCPClientSocketLibevent::GetPeerAddress(AddressList* address) const { return OK; } +int TCPClientSocketLibevent::GetLocalAddress(IPEndPoint* address) const { + DCHECK(CalledOnValidThread()); + DCHECK(address); + if (!IsConnected()) + return ERR_SOCKET_NOT_CONNECTED; + + struct sockaddr_storage addr_storage; + socklen_t addr_len = sizeof(addr_storage); + struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&addr_storage); + if (getsockname(socket_, addr, &addr_len)) + return MapSystemError(errno); + if (!address->FromSockAddr(addr, addr_len)) + return ERR_FAILED; + + return OK; +} + const BoundNetLog& TCPClientSocketLibevent::NetLog() const { return net_log_; } diff --git a/net/socket/tcp_client_socket_libevent.h b/net/socket/tcp_client_socket_libevent.h index 796a4a8..89ffac1 100644 --- a/net/socket/tcp_client_socket_libevent.h +++ b/net/socket/tcp_client_socket_libevent.h @@ -46,6 +46,7 @@ class TCPClientSocketLibevent : public ClientSocket, base::NonThreadSafe { virtual bool IsConnected() const; virtual bool IsConnectedAndIdle() const; virtual int GetPeerAddress(AddressList* address) const; + virtual int GetLocalAddress(IPEndPoint* address) const; virtual const BoundNetLog& NetLog() const; virtual void SetSubresourceSpeculation(); virtual void SetOmniboxSpeculation(); diff --git a/net/socket/tcp_client_socket_win.cc b/net/socket/tcp_client_socket_win.cc index eec7dbb..de5ff61 100644 --- a/net/socket/tcp_client_socket_win.cc +++ b/net/socket/tcp_client_socket_win.cc @@ -16,6 +16,7 @@ #include "net/base/address_list_net_log_param.h" #include "net/base/connection_type_histograms.h" #include "net/base/io_buffer.h" +#include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" #include "net/base/net_log.h" #include "net/base/net_util.h" @@ -471,6 +472,22 @@ int TCPClientSocketWin::GetPeerAddress(AddressList* address) const { return OK; } +int TCPClientSocketWin::GetLocalAddress(IPEndPoint* address) const { + DCHECK(CalledOnValidThread()); + DCHECK(address); + if (!IsConnected()) + return ERR_SOCKET_NOT_CONNECTED; + + struct sockaddr_storage addr_storage; + socklen_t addr_len = sizeof(addr_storage); + struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&addr_storage); + if (getsockname(socket_, addr, &addr_len)) + return MapSystemError(WSAGetLastError()); + if (!address->FromSockAddr(addr, addr_len)) + return ERR_FAILED; + return OK; +} + void TCPClientSocketWin::SetSubresourceSpeculation() { use_history_.set_subresource_speculation(); } diff --git a/net/socket/tcp_client_socket_win.h b/net/socket/tcp_client_socket_win.h index bca0d30..8beb983 100644 --- a/net/socket/tcp_client_socket_win.h +++ b/net/socket/tcp_client_socket_win.h @@ -42,6 +42,7 @@ class TCPClientSocketWin : public ClientSocket, base::NonThreadSafe { virtual bool IsConnected() const; virtual bool IsConnectedAndIdle() const; virtual int GetPeerAddress(AddressList* address) const; + virtual int GetLocalAddress(IPEndPoint* address) const; virtual const BoundNetLog& NetLog() const { return net_log_; } virtual void SetSubresourceSpeculation(); virtual void SetOmniboxSpeculation(); diff --git a/net/socket/transport_client_socket_pool_unittest.cc b/net/socket/transport_client_socket_pool_unittest.cc index 889cc5b..ae937e9 100644 --- a/net/socket/transport_client_socket_pool_unittest.cc +++ b/net/socket/transport_client_socket_pool_unittest.cc @@ -50,6 +50,9 @@ class MockClientSocket : public ClientSocket { virtual int GetPeerAddress(AddressList* address) const { return ERR_UNEXPECTED; } + virtual int GetLocalAddress(IPEndPoint* address) const { + return ERR_UNEXPECTED; + } virtual const BoundNetLog& NetLog() const { return net_log_; } @@ -96,6 +99,9 @@ class MockFailingClientSocket : public ClientSocket { virtual int GetPeerAddress(AddressList* address) const { return ERR_UNEXPECTED; } + virtual int GetLocalAddress(IPEndPoint* address) const { + return ERR_UNEXPECTED; + } virtual const BoundNetLog& NetLog() const { return net_log_; } @@ -155,6 +161,9 @@ class MockPendingClientSocket : public ClientSocket { virtual int GetPeerAddress(AddressList* address) const { return ERR_UNEXPECTED; } + virtual int GetLocalAddress(IPEndPoint* address) const { + return ERR_UNEXPECTED; + } virtual const BoundNetLog& NetLog() const { return net_log_; } |