Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #2770 from t4-ravenbird/woa-mac-discovery

wake-on-access ; avoid attempting mac-discovery for internet addresses
  • Loading branch information...
commit 1238bb3988df978ea2f27b7f03c9a2dfdcc0a0ec 2 parents 571e69a + b8c290d
@MartijnKaijser MartijnKaijser authored
View
8 xbmc/network/WakeOnAccess.cpp
@@ -38,6 +38,7 @@
#include "utils/JobManager.h"
#include "utils/log.h"
#include "utils/XMLUtils.h"
+#include "utils/URIUtils.h"
#include "WakeOnAccess.h"
@@ -487,7 +488,12 @@ static void AddHostFromDatabase(const DatabaseSettings& setting, vector<string>&
void CWakeOnAccess::QueueMACDiscoveryForHost(const CStdString& host)
{
if (IsEnabled())
- CJobManager::GetInstance().AddJob(new CMACDiscoveryJob(host), this);
+ {
+ if (URIUtils::IsHostOnLAN(host, true))
+ CJobManager::GetInstance().AddJob(new CMACDiscoveryJob(host), this);
+ else
+ CLog::Log(LOGNOTICE, "%s - skip Mac discovery for non-local host '%s'", __FUNCTION__, host.c_str());
+ }
}
static void AddHostsFromMediaSource(const CMediaSource& source, std::vector<std::string>& hosts)
View
24 xbmc/utils/URIUtils.cpp
@@ -494,6 +494,19 @@ bool URIUtils::IsOnLAN(const CStdString& strPath)
return false;
CStdString host = url.GetHostName();
+
+ return IsHostOnLAN(host);
+}
+
+static bool addr_match(uint32_t addr, const char* target, const char* submask)
+{
+ uint32_t addr2 = ntohl(inet_addr(target));
+ uint32_t mask = ntohl(inet_addr(submask));
+ return (addr & mask) == (addr2 & mask);
+}
+
+bool URIUtils::IsHostOnLAN(const CStdString& host, bool offLineCheck)
+{
if(host.length() == 0)
return false;
@@ -502,7 +515,7 @@ bool URIUtils::IsOnLAN(const CStdString& strPath)
if(host.find('.') == string::npos)
return true;
- unsigned long address = ntohl(inet_addr(host.c_str()));
+ uint32_t address = ntohl(inet_addr(host.c_str()));
if(address == INADDR_NONE)
{
CStdString ip;
@@ -512,6 +525,15 @@ bool URIUtils::IsOnLAN(const CStdString& strPath)
if(address != INADDR_NONE)
{
+ if (offLineCheck) // check if in private range, ref https://en.wikipedia.org/wiki/Private_network
+ {
+ if (
+ addr_match(address, "192.168.0.0", "255.255.0.0") ||
+ addr_match(address, "10.0.0.0", "255.0.0.0") ||
+ addr_match(address, "172.16.0.0", "255.240.0.0")
+ )
+ return true;
+ }
// check if we are on the local subnet
if (!g_application.getNetwork().GetFirstConnectedInterface())
return false;
View
1  xbmc/utils/URIUtils.h
@@ -95,6 +95,7 @@ class URIUtils
static bool IsAfp(const CStdString& strFile);
static bool IsOnDVD(const CStdString& strFile);
static bool IsOnLAN(const CStdString& strFile);
+ static bool IsHostOnLAN(const CStdString& hostName, bool offLineCheck = false);
static bool IsPlugin(const CStdString& strFile);
static bool IsScript(const CStdString& strFile);
static bool IsRAR(const CStdString& strFile);
Please sign in to comment.
Something went wrong with that request. Please try again.