فهرست منبع

#98 Fixed bug in the computation of free IP addresses for a given subnet

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@419 a333f486-631f-4898-b8df-5754b55c2be0
romainq 15 سال پیش
والد
کامیت
7ac07fe194
1فایلهای تغییر یافته به همراه19 افزوده شده و 12 حذف شده
  1. 19 12
      business/itop.business.class.inc.php

+ 19 - 12
business/itop.business.class.inc.php

@@ -836,8 +836,12 @@ class bizSubnet extends logInfra
 
 		$bit_ip = ip2long($this->Get('ip'));
 		$bit_mask = ip2long($this->Get('mask'));
-		$sIPMin = long2ip($bit_ip & $bit_mask);
-		$sIPMax = long2ip(($bit_ip | (~$bit_mask)) - 1);
+
+		$iIPMin = $bit_ip & $bit_mask;
+		$iIPMax = ($bit_ip | (~$bit_mask)) - 1;
+
+		$sIPMin = long2ip($iIPMin);
+		$sIPMax = long2ip($iIPMax);
 
 		$oPage->p("Interfaces having an IP in the range: <em>$sIPMin</em> to <em>$sIPMax</em>");
 		
@@ -845,7 +849,7 @@ class bizSubnet extends logInfra
 		self::DisplaySet($oPage, $oIfSet);
 
 		$iCountUsed = $oIfSet->Count();
-		$iCountRange = ip2long($sIPMax) - ip2long($sIPMin);
+		$iCountRange = $iIPMax - $iIPMin;
 		$iFreeCount =  $iCountRange - $iCountUsed;
 
 		$oPage->SetCurrentTab('Free IPs');
@@ -853,18 +857,21 @@ class bizSubnet extends logInfra
 		$oPage->p("Here is an extract of 10 free IP addresses");
 
 		$aUsedIPs = $oIfSet->GetColumnAsArray('ip_address', false);
-		$i = 0;
-		while ($i < min($iFreeCount, 10))
+		$iAnIP = $iIPMin;
+		$iFound = 0;
+		while (($iFound < min($iFreeCount, 10)) && ($iAnIP <= $iIPMax))
 		{
-			$i++;
-
-			$iAnIP = ip2long($sIPMin) + $i;
-			if (in_array($iAnIP, $aUsedIPs)) continue;
-
 			$sAnIP = long2ip($iAnIP);
-			$oPage->p($sAnIP);
+			if (!in_array($sAnIP, $aUsedIPs))
+			{
+				$iFound++;
+				$oPage->p($sAnIP);
+			}
+			else
+			{
+			}
+			$iAnIP++;
 		}
-		
 	}
 }