diff options
author | Hans Wennborg <hans@hanshq.net> | 2017-08-29 20:33:27 +0300 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2017-08-29 20:33:27 +0300 |
commit | f0701b2b859137dd743fd0a69e26ea7eff3e53a7 (patch) | |
tree | 745fe3863577a05cfef5522cc66fa45b3da0b7ed | |
parent | 828b6813144ea5d1dbf13168d8f79faa838fb49a (diff) |
Merging r312008:
------------------------------------------------------------------------
r312008 | cbieneman | 2017-08-29 09:13:41 -0700 (Tue, 29 Aug 2017) | 7 lines
[IPv6] Fix a bug in the IPv6 listen behavior
The socket bind address should either be localhost or anyaddress. This bug in the listen behavior was preventing lldb-server from opening sockets for non-localhost connections.
The added test verifies that opening an anyaddress socket works and has a non-zero port assignment.
This should resolve PR34183.
------------------------------------------------------------------------
llvm-svn: 312016
-rw-r--r-- | lldb/source/Host/common/TCPSocket.cpp | 11 | ||||
-rw-r--r-- | lldb/unittests/Host/SocketTest.cpp | 11 |
2 files changed, 19 insertions, 3 deletions
diff --git a/lldb/source/Host/common/TCPSocket.cpp b/lldb/source/Host/common/TCPSocket.cpp index a7af93f10a7f..f896944bb1b3 100644 --- a/lldb/source/Host/common/TCPSocket.cpp +++ b/lldb/source/Host/common/TCPSocket.cpp @@ -198,9 +198,14 @@ Status TCPSocket::Listen(llvm::StringRef name, int backlog) { ::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, option_value_p, sizeof(option_value)); - address.SetPort(port); - - int err = ::bind(fd, &address.sockaddr(), address.GetLength()); + SocketAddress listen_address = address; + if(!listen_address.IsLocalhost()) + listen_address.SetToAnyAddress(address.GetFamily(), port); + else + listen_address.SetPort(port); + + int err = + ::bind(fd, &listen_address.sockaddr(), listen_address.GetLength()); if (-1 != err) err = ::listen(fd, backlog); diff --git a/lldb/unittests/Host/SocketTest.cpp b/lldb/unittests/Host/SocketTest.cpp index d8fdc593ed46..59f59fc0ada7 100644 --- a/lldb/unittests/Host/SocketTest.cpp +++ b/lldb/unittests/Host/SocketTest.cpp @@ -220,3 +220,14 @@ TEST_F(SocketTest, UDPConnect) { EXPECT_TRUE(error.Success()); EXPECT_TRUE(socket_up->IsValid()); } + +TEST_F(SocketTest, TCPListen0GetPort) { + Socket *server_socket; + Predicate<uint16_t> port_predicate; + port_predicate.SetValue(0, eBroadcastNever); + Status err = + Socket::TcpListen("10.10.12.3:0", false, server_socket, &port_predicate); + std::unique_ptr<TCPSocket> socket_up((TCPSocket*)server_socket); + EXPECT_TRUE(socket_up->IsValid()); + EXPECT_NE(socket_up->GetLocalPortNumber(), 0); +} |