From 7fb2e196783195461006550741e04131769104cd Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 25 Feb 2020 11:04:59 +0100 Subject: [PATCH] dnsdist: Make the Proxy Protocol tests compatible with Python 2 --- regression-tests.dnsdist/proxyprotocol.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/regression-tests.dnsdist/proxyprotocol.py b/regression-tests.dnsdist/proxyprotocol.py index cc34b9f16c..a7a74907a8 100644 --- a/regression-tests.dnsdist/proxyprotocol.py +++ b/regression-tests.dnsdist/proxyprotocol.py @@ -19,18 +19,20 @@ class ProxyProtocol(object): if data[:len(self.MAGIC)] != self.MAGIC: return False - self.version = int(data[12]) >> 4 + value = struct.unpack('!B', bytes(bytearray([data[12]])))[0] + self.version = value >> 4 if self.version != 0x02: return False - self.command = int(data[12]) & ~0x20 + self.command = value & ~0x20 self.local = False self.offset = self.HEADER_SIZE if self.command == 0x00: self.local = True elif self.command == 0x01: - self.family = int(data[13]) >> 4 + value = struct.unpack('!B', bytes(bytearray([data[13]])))[0] + self.family = value >> 4 if self.family == 0x01: self.addrSize = 4 elif self.family == 0x02: @@ -38,7 +40,7 @@ class ProxyProtocol(object): else: return False - self.protocol = int(data[13]) & ~0xF0 + self.protocol = value & ~0xF0 if self.protocol == 0x01: self.tcp = True elif self.protocol == 0x02: @@ -103,7 +105,7 @@ class ProxyProtocol(object): return False while remaining >= 3: - valueType = data[self.offset] + valueType = struct.unpack("!B", bytes(bytearray([data[self.offset]])))[0] self.offset = self.offset + 1 valueLen = struct.unpack("!H", data[self.offset:self.offset+2])[0] self.offset = self.offset + 2 -- 2.39.5