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
This commit is contained in:
Greg Clayton 2015-07-24 16:55:00 +00:00
parent fa8e3a551f
commit fceca9b539
1 changed files with 18 additions and 9 deletions

View File

@ -201,12 +201,12 @@ Error Socket::TcpConnect(llvm::StringRef host_and_port, bool child_processes_inh
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 @@ Error Socket::TcpListen(
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);