[Lldb-commits] [lldb] r312008 - [IPv6] Fix a bug in the IPv6 listen behavior

Hans Wennborg via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 29 10:34:41 PDT 2017


Merged to 5.0 in r312016.

On Tue, Aug 29, 2017 at 9:13 AM, Chris Bieneman via lldb-commits
<lldb-commits at lists.llvm.org> wrote:
> Author: cbieneman
> Date: Tue Aug 29 09:13:41 2017
> New Revision: 312008
>
> URL: http://llvm.org/viewvc/llvm-project?rev=312008&view=rev
> Log:
> [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.
>
> Modified:
>     lldb/trunk/source/Host/common/TCPSocket.cpp
>     lldb/trunk/unittests/Host/SocketTest.cpp
>
> Modified: lldb/trunk/source/Host/common/TCPSocket.cpp
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/TCPSocket.cpp?rev=312008&r1=312007&r2=312008&view=diff
> ==============================================================================
> --- lldb/trunk/source/Host/common/TCPSocket.cpp (original)
> +++ lldb/trunk/source/Host/common/TCPSocket.cpp Tue Aug 29 09:13:41 2017
> @@ -198,9 +198,14 @@ Status TCPSocket::Listen(llvm::StringRef
>      ::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, option_value_p,
>                   sizeof(option_value));
>
> -    address.SetPort(port);
> +    SocketAddress listen_address = address;
> +    if(!listen_address.IsLocalhost())
> +      listen_address.SetToAnyAddress(address.GetFamily(), port);
> +    else
> +      listen_address.SetPort(port);
>
> -    int err = ::bind(fd, &address.sockaddr(), address.GetLength());
> +    int err =
> +        ::bind(fd, &listen_address.sockaddr(), listen_address.GetLength());
>      if (-1 != err)
>        err = ::listen(fd, backlog);
>
>
> Modified: lldb/trunk/unittests/Host/SocketTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/SocketTest.cpp?rev=312008&r1=312007&r2=312008&view=diff
> ==============================================================================
> --- lldb/trunk/unittests/Host/SocketTest.cpp (original)
> +++ lldb/trunk/unittests/Host/SocketTest.cpp Tue Aug 29 09:13:41 2017
> @@ -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);
> +}
>
>
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


More information about the lldb-commits mailing list