From 06643bbbf315c2f63b73317e3dca5583170833dc Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 27 Jul 2021 00:51:22 +0300 Subject: [PATCH] Do ord() on first two bytes of host in checkIPv6Address() only in python2 --- src/protocol.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/protocol.py b/src/protocol.py index d80bd7bf..e2d80512 100644 --- a/src/protocol.py +++ b/src/protocol.py @@ -202,15 +202,19 @@ def checkIPv6Address(host, hostStandardFormat, private=False): Returns hostStandardFormat if it is an IPv6 address, otherwise returns False """ - if host == (b'\x00' * 15) + b'\x01': + if host == b'\x00' * 15 + b'\x01': if not private: logger.debug('Ignoring loopback address: %s', hostStandardFormat) return False - if host[0] == b'\xFE' and (ord(host[1]) & 0xc0) == 0x80: + try: + host = [ord(c) for c in host[:2]] + except TypeError: # python3 has ints already + pass + if host[0] == 0xfe and host[1] & 0xc0 == 0x80: if not private: logger.debug('Ignoring local address: %s', hostStandardFormat) return hostStandardFormat if private else False - if (ord(host[0]) & 0xfe) == 0xfc: + if host[0] & 0xfe == 0xfc: if not private: logger.debug( 'Ignoring unique local address: %s', hostStandardFormat)