mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-21 01:24:21 +00:00
Fixed a bug where StreamingSocket::isLocal would only return true if it was connected to 127.0.0.1
This commit is contained in:
parent
1e2cb6f6f7
commit
6340e541f0
1 changed files with 24 additions and 1 deletions
|
|
@ -169,6 +169,17 @@ namespace SocketHelpers
|
|||
return -1;
|
||||
}
|
||||
|
||||
static String getConnectedAddress (const SocketHandle handle) noexcept
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
socklen_t len = sizeof (addr);
|
||||
|
||||
if (getpeername (handle, (struct sockaddr*) &addr, &len) >= 0)
|
||||
return inet_ntoa (addr.sin_addr);
|
||||
|
||||
return String ("0.0.0.0");
|
||||
}
|
||||
|
||||
static int readSocket (const SocketHandle handle,
|
||||
void* const destBuffer, const int maxBytesToRead,
|
||||
bool volatile& connected,
|
||||
|
|
@ -576,7 +587,19 @@ StreamingSocket* StreamingSocket::waitForNextConnection() const
|
|||
|
||||
bool StreamingSocket::isLocal() const noexcept
|
||||
{
|
||||
return hostName == "127.0.0.1";
|
||||
if (! isConnected())
|
||||
return false;
|
||||
|
||||
Array<IPAddress> localAddresses;
|
||||
IPAddress::findAllAddresses (localAddresses);
|
||||
IPAddress currentIP (SocketHelpers::getConnectedAddress (handle));
|
||||
|
||||
const int n = localAddresses.size();
|
||||
for (int i = 0; i < n; ++i)
|
||||
if (localAddresses.getReference (i) == currentIP)
|
||||
return true;
|
||||
|
||||
return (hostName == "127.0.0.1");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue