Browse Source

Small Improvements in PcapAddressOperations

Marcel 7 years ago
parent
commit
90e7d23fb1
1 changed files with 6 additions and 3 deletions
  1. 6 3
      code/ID2TLib/PcapAddressOperations.py

+ 6 - 3
code/ID2TLib/PcapAddressOperations.py

@@ -81,8 +81,8 @@ class PcapAddressOperations():
         """
 
         # add more unused local ips to the pool, if needed
-        if len(self.unused_local_ips) < 10:
-            self.expand_unused_local_ips()
+        while len(self.unused_local_ips) < count and self.expand_unused_local_ips() == True:
+            pass
 
         unused_local_ips = self.unused_local_ips
         uncertain_local_ips = self.uncertain_local_ips
@@ -191,7 +191,10 @@ class PcapAddressOperations():
         # to do that, divide the unused local Addressspace into chunks of (chunks_size) Addresses
         # initally only the first chunk will be used, but more chunks can be added to the pool of unused_local_ips if needed
         self.min_local_ip, self.max_local_ip = min(local_ips), max(local_ips)
-        local_ip_range = (self.max_local_ip.to_int() - 1) - (self.min_local_ip.to_int() + 1) # boundaries are inclusive
+        local_ip_range = (self.max_local_ip.to_int()) - (self.min_local_ip.to_int() + 1)
+        if local_ip_range < 0:
+            # for min,max pairs like (1,1), (1,2) there is no free address in between, but for (1,1) local_ip_range may be -1, because 1-(1+1)=-1
+            local_ip_range = 0
 
         # chunk size can be adjusted if needed
         self.chunk_size = 200