Skip to content

Commit 7ae5dfd

Browse files
committed
Do ord() on first two bytes of host in checkIPv6Address() only in python2
1 parent d3ee553 commit 7ae5dfd

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/protocol.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,19 @@ def checkIPv6Address(host, hostStandardFormat, private=False):
202202
Returns hostStandardFormat if it is an IPv6 address,
203203
otherwise returns False
204204
"""
205-
if host == (b'\x00' * 15) + b'\x01':
205+
if host == b'\x00' * 15 + b'\x01':
206206
if not private:
207207
logger.debug('Ignoring loopback address: %s', hostStandardFormat)
208208
return False
209-
if host[0] == b'\xFE' and (ord(host[1]) & 0xc0) == 0x80:
209+
try:
210+
host = [ord(c) for c in host[:2]]
211+
except TypeError: # python3 has ints already
212+
pass
213+
if host[0:1] == b'\xFE' and host[1] & 0xc0 == 0x80:
210214
if not private:
211215
logger.debug('Ignoring local address: %s', hostStandardFormat)
212216
return hostStandardFormat if private else False
213-
if (ord(host[0]) & 0xfe) == 0xfc:
217+
if host[0] & 0xfe == 0xfc:
214218
if not private:
215219
logger.debug(
216220
'Ignoring unique local address: %s', hostStandardFormat)

0 commit comments

Comments
 (0)