Bind to the loopback when we are expecting a connection from 127.0.0.1 so we don't set off firewall protections.

<rdar://problem/17897318>

llvm-svn: 243118
diff --git a/lldb/source/Host/common/Socket.cpp b/lldb/source/Host/common/Socket.cpp
index 6620dab..37b6cd5 100644
--- a/lldb/source/Host/common/Socket.cpp
+++ b/lldb/source/Host/common/Socket.cpp
@@ -201,12 +201,12 @@
     return error;
 }
 
-Error Socket::TcpListen(
-    llvm::StringRef host_and_port,
-    bool child_processes_inherit,
-    Socket *&socket,
-    Predicate<uint16_t>* predicate,
-    int backlog)
+Error
+Socket::TcpListen (llvm::StringRef host_and_port,
+                   bool child_processes_inherit,
+                   Socket *&socket,
+                   Predicate<uint16_t>* predicate,
+                   int backlog)
 {
     std::unique_ptr<Socket> listen_socket;
     NativeSocket listen_sock = kInvalidSocketValue;
@@ -237,10 +237,19 @@
     if (!DecodeHostAndPort (host_and_port, host_str, port_str, port, &error))
         return error;
 
-    SocketAddress anyaddr;
-    if (anyaddr.SetToAnyAddress (family, port))
+    SocketAddress bind_addr;
+    bool bind_addr_success = false;
+
+    // Only bind to the loopback address if we are expecting a connection from
+    // localhost to avoid any firewall issues.
+    if (host_str == "127.0.0.1")
+        bind_addr_success = bind_addr.SetToLocalhost (family, port);
+    else
+        bind_addr_success = bind_addr.SetToAnyAddress (family, port);
+
+    if (bind_addr_success)
     {
-        int err = ::bind (listen_sock, anyaddr, anyaddr.GetLength());
+        int err = ::bind (listen_sock, bind_addr, bind_addr.GetLength());
         if (err == -1)
         {
             SetLastError (error);