Skip to content
This repository
Browse code

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
Martijn Kaijser authored October 01, 2013
8  xbmc/network/WakeOnAccess.cpp
@@ -38,6 +38,7 @@
38 38
 #include "utils/JobManager.h"
39 39
 #include "utils/log.h"
40 40
 #include "utils/XMLUtils.h"
  41
+#include "utils/URIUtils.h"
41 42
 
42 43
 #include "WakeOnAccess.h"
43 44
 
@@ -487,7 +488,12 @@ static void AddHostFromDatabase(const DatabaseSettings& setting, vector<string>&
487 488
 void CWakeOnAccess::QueueMACDiscoveryForHost(const CStdString& host)
488 489
 {
489 490
   if (IsEnabled())
490  
-    CJobManager::GetInstance().AddJob(new CMACDiscoveryJob(host), this);
  491
+  {
  492
+    if (URIUtils::IsHostOnLAN(host, true))
  493
+      CJobManager::GetInstance().AddJob(new CMACDiscoveryJob(host), this);
  494
+    else
  495
+      CLog::Log(LOGNOTICE, "%s - skip Mac discovery for non-local host '%s'", __FUNCTION__, host.c_str());
  496
+  }
491 497
 }
492 498
 
493 499
 static void AddHostsFromMediaSource(const CMediaSource& source, std::vector<std::string>& hosts)
24  xbmc/utils/URIUtils.cpp
@@ -494,6 +494,19 @@ bool URIUtils::IsOnLAN(const CStdString& strPath)
494 494
     return false;
495 495
 
496 496
   CStdString host = url.GetHostName();
  497
+
  498
+  return IsHostOnLAN(host);
  499
+}
  500
+
  501
+static bool addr_match(uint32_t addr, const char* target, const char* submask)
  502
+{
  503
+  uint32_t addr2 = ntohl(inet_addr(target));
  504
+  uint32_t mask = ntohl(inet_addr(submask));
  505
+  return (addr & mask) == (addr2 & mask);
  506
+}
  507
+
  508
+bool URIUtils::IsHostOnLAN(const CStdString& host, bool offLineCheck)
  509
+{
497 510
   if(host.length() == 0)
498 511
     return false;
499 512
 
@@ -502,7 +515,7 @@ bool URIUtils::IsOnLAN(const CStdString& strPath)
502 515
   if(host.find('.') == string::npos)
503 516
     return true;
504 517
 
505  
-  unsigned long address = ntohl(inet_addr(host.c_str()));
  518
+  uint32_t address = ntohl(inet_addr(host.c_str()));
506 519
   if(address == INADDR_NONE)
507 520
   {
508 521
     CStdString ip;
@@ -512,6 +525,15 @@ bool URIUtils::IsOnLAN(const CStdString& strPath)
512 525
 
513 526
   if(address != INADDR_NONE)
514 527
   {
  528
+    if (offLineCheck) // check if in private range, ref https://en.wikipedia.org/wiki/Private_network
  529
+    {
  530
+      if (
  531
+        addr_match(address, "192.168.0.0", "255.255.0.0") ||
  532
+        addr_match(address, "10.0.0.0", "255.0.0.0") ||
  533
+        addr_match(address, "172.16.0.0", "255.240.0.0")
  534
+        )
  535
+        return true;
  536
+    }
515 537
     // check if we are on the local subnet
516 538
     if (!g_application.getNetwork().GetFirstConnectedInterface())
517 539
       return false;
1  xbmc/utils/URIUtils.h
@@ -95,6 +95,7 @@ class URIUtils
95 95
   static bool IsAfp(const CStdString& strFile);    
96 96
   static bool IsOnDVD(const CStdString& strFile);
97 97
   static bool IsOnLAN(const CStdString& strFile);
  98
+  static bool IsHostOnLAN(const CStdString& hostName, bool offLineCheck = false);
98 99
   static bool IsPlugin(const CStdString& strFile);
99 100
   static bool IsScript(const CStdString& strFile);
100 101
   static bool IsRAR(const CStdString& strFile);

0 notes on commit 1238bb3

Please sign in to comment.
Something went wrong with that request. Please try again.