diff options
| author | Chris Bieneman <beanz@apple.com> | 2017-08-29 16:13:41 +0000 |
|---|---|---|
| committer | Chris Bieneman <beanz@apple.com> | 2017-08-29 16:13:41 +0000 |
| commit | c6f6aa441b1fb0ed47b3275cd02e158a61e252ac (patch) | |
| tree | 511b552dd7d5ce3e07d35c5569102359036a964d | |
| parent | 734d8548ee93d053be45b36b612a737e6e4c61d3 (diff) | |
| download | bcm5719-llvm-c6f6aa441b1fb0ed47b3275cd02e158a61e252ac.tar.gz bcm5719-llvm-c6f6aa441b1fb0ed47b3275cd02e158a61e252ac.zip | |
[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: 312008
| -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 a7af93f10a7..f896944bb1b 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 d8fdc593ed4..59f59fc0ada 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); +} |

