Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing hextet/octet value checks

IPv6 address/mask hextets can contain 0x0 and 0xffff
IPv4 address/mask octets can contain 0 and 255
  • Loading branch information...
commit 3cdab4516197cf763dcfcfd3811020ca232b2eeb 1 parent 2159ee1
@mattbennett mattbennett authored
Showing with 2 additions and 2 deletions.
  1. +2 −2 src/ipcalc.py
View
4 src/ipcalc.py
@@ -285,7 +285,7 @@ def _dqtoi(self, dq):
for h in hx:
if len(h) < 4:
h = '%04x' % int(h, 16)
- if not 0 < int(h, 16) < 0xffff:
+ if not 0 <= int(h, 16) <= 0xffff:
raise ValueError, "%r: IPv6 address invalid: hextets should be between 0x0000 and 0xffff" % dq
ip += h
self.v = 6
@@ -302,7 +302,7 @@ def _dqtoi(self, dq):
if len(q) > 4:
raise ValueError, "%r: IPv4 address invalid: more than 4 bytes" % dq
for x in q:
- if not 0 < int(x) < 255:
+ if not 0 <= int(x) <= 255:
raise ValueError, "%r: IPv4 address invalid: bytes should be between 0 and 255" % dq
while len(q) < 4:
q.insert(1, '0')
Please sign in to comment.
Something went wrong with that request. Please try again.