Skip to content

Commit

Permalink
Handle netmask of 0 (close #41)
Browse files Browse the repository at this point in the history
  • Loading branch information
tehmaze committed Jul 14, 2015
1 parent 4fe05f5 commit 7b28c8a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ipcalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,13 @@ def __init__(self, ip, mask=None, version=0):
elif isinstance(self.mask, basestring):
limit = [32, 128][':' in self.mask]
inverted = ~self._dqtoi(self.mask)
count = 0
while inverted & pow(2, count):
count += 1
self.mask = (limit - count)
if inverted == -1:
self.mask = 0
else:
count = 0
while inverted & pow(2, count):
count += 1
self.mask = (limit - count)
else:
raise ValueError('Invalid netmask')
# Validate subnet size
Expand Down

0 comments on commit 7b28c8a

Please sign in to comment.