From b612d8d9f626eeae3bc7eb2a10c139c4d79f381d Mon Sep 17 00:00:00 2001
From: gpotter2 <gabriel@potter.fr>
Date: Tue, 19 Sep 2017 00:03:26 +0200
Subject: [PATCH] More chr/chb and ord/orb changes

---
 scapy/arch/__init__.py      |  2 +-
 scapy/arch/pcapdnet.py      |  2 +-
 scapy/asn1/ber.py           |  2 +-
 scapy/automaton.py          |  4 +-
 scapy/compat.py             |  4 +-
 scapy/fields.py             |  2 +-
 scapy/layers/dhcp6.py       | 10 ++--
 scapy/layers/dns.py         | 10 ++--
 scapy/layers/eap.py         |  6 +--
 scapy/layers/inet.py        |  8 ++--
 scapy/layers/inet6.py       | 30 ++++++------
 scapy/layers/l2.py          |  2 +-
 scapy/layers/llmnr.py       |  2 +-
 scapy/layers/lltd.py        |  7 ++-
 scapy/layers/ppp.py         | 12 ++---
 scapy/layers/radius.py      |  4 +-
 scapy/layers/sctp.py        | 10 ++--
 scapy/layers/tls/session.py |  2 +-
 scapy/layers/vrrp.py        |  6 +--
 scapy/route6.py             |  2 +-
 scapy/utils.py              | 10 ++--
 scapy/utils6.py             |  4 +-
 test/regression.uts         | 92 ++++++++++++++++++-------------------
 23 files changed, 116 insertions(+), 117 deletions(-)

diff --git a/scapy/arch/__init__.py b/scapy/arch/__init__.py
index 9a7ff230..7095283f 100644
--- a/scapy/arch/__init__.py
+++ b/scapy/arch/__init__.py
@@ -19,7 +19,7 @@ from scapy.pton_ntop import inet_pton
 from scapy.data import *
 
 def str2mac(s):
-    return ("%02x:"*6)[:-1] % tuple(ord(x) for x in s)
+    return ("%02x:"*6)[:-1] % tuple(orb(x) for x in s)
 
 if not WINDOWS:
     if not scapy.config.conf.use_pcap and not scapy.config.conf.use_dnet:
diff --git a/scapy/arch/pcapdnet.py b/scapy/arch/pcapdnet.py
index b9c4608b..0e28f0b3 100644
--- a/scapy/arch/pcapdnet.py
+++ b/scapy/arch/pcapdnet.py
@@ -129,7 +129,7 @@ if conf.use_winpcapy:
           if a.contents.addr.contents.sa_family == socket.AF_INET6:
             ap = a.contents.addr
             val = cast(ap, POINTER(sockaddr_in6))
-            addr = inet_ntop(socket.AF_INET6, "".join(chr(x) for x in val.contents.sin6_addr[:]))
+            addr = inet_ntop(socket.AF_INET6, b"".join(chb(x) for x in val.contents.sin6_addr[:]))
             scope = scapy.utils6.in6_getscope(addr)
             ret.append((addr, scope, p.contents.name.decode('ascii')))
           a = a.contents.next
diff --git a/scapy/asn1/ber.py b/scapy/asn1/ber.py
index 295d300b..4ca705ec 100644
--- a/scapy/asn1/ber.py
+++ b/scapy/asn1/ber.py
@@ -337,7 +337,7 @@ class BERcodec_STRING(BERcodec_Object):
     tag = ASN1_Class_UNIVERSAL.STRING
     @classmethod
     def enc(cls,s):
-        return chb(hash(cls.tag))+BER_len_enc(len(s))+s
+        return chb(hash(cls.tag))+BER_len_enc(len(s))+raw(s) # Be sure we are encoding bytes
     @classmethod
     def do_dec(cls, s, context=None, safe=False):
         l,s,t = cls.check_type_check_len(s)
diff --git a/scapy/automaton.py b/scapy/automaton.py
index 35046e3a..e2d0589c 100644
--- a/scapy/automaton.py
+++ b/scapy/automaton.py
@@ -644,11 +644,11 @@ class Automaton(six.with_metaclass(Automaton_metaclass)):
             ioin,ioout = extfd                
             if ioin is None:
                 ioin = ObjectPipe()
-            elif not isinstance(ioin, types.InstanceType):
+            elif not isinstance(ioin, SelectableObject):
                 ioin = self._IO_fdwrapper(ioin,None)
             if ioout is None:
                 ioout = ioin if WINDOWS else ObjectPipe()
-            elif not isinstance(ioout, types.InstanceType):
+            elif not isinstance(ioout, SelectableObject):
                 ioout = self._IO_fdwrapper(None,ioout)
 
             self.ioin[n] = ioin
diff --git a/scapy/compat.py b/scapy/compat.py
index 7cc96da4..8cb64393 100644
--- a/scapy/compat.py
+++ b/scapy/compat.py
@@ -109,7 +109,7 @@ else:
             return bytes([x])
 
 def bytes_codec(x, codec, force_str=False):
-    """Hexify a str or a bytes object"""
+    """Encode a str or a bytes object with a codec"""
     if six.PY2:
         return str(x).encode(codec)
     else:
@@ -119,7 +119,7 @@ def bytes_codec(x, codec, force_str=False):
         return hex_
 
 def codec_bytes(x, codec):
-    """De-hexify a str or a byte object"""
+    """Decode a str or a byte object with a codec"""
     if six.PY2:
         return str(x).decode(codec)
     else:
diff --git a/scapy/fields.py b/scapy/fields.py
index 2bfe605b..80506f6a 100644
--- a/scapy/fields.py
+++ b/scapy/fields.py
@@ -385,7 +385,7 @@ class StrField(Field):
         if x is None:
             x = b""
         elif not isinstance(x, bytes):
-            x = bytes(x)
+            x = raw(x)
         return x
     def addfield(self, pkt, s, val):
         return s + self.i2m(pkt, val)
diff --git a/scapy/layers/dhcp6.py b/scapy/layers/dhcp6.py
index 236c2df8..3ffe4296 100644
--- a/scapy/layers/dhcp6.py
+++ b/scapy/layers/dhcp6.py
@@ -736,16 +736,16 @@ class DomainNameField(StrLenField):
     def m2i(self, pkt, x):
         cur = []
         while x:
-            l = ord(x[0])
+            l = orb(x[0])
             cur.append(x[1:1+l])
             x = x[l+1:]
-        ret_str = ".".join(cur)
-        return ret_str
+        ret_str = b".".join(cur)
+        return plain_str(ret_str)
 
     def i2m(self, pkt, x):
         if not x:
             return b""
-        return b"".join(chb(len(z)) + z for z in x.split('.'))
+        return b"".join(chb(len(z)) + z.encode("utf8") for z in x.split('.'))
 
 class DHCP6OptNISDomain(_DHCP6OptGuessPayload):             #RFC3898
     name = "DHCP6 Option - NIS Domain Name"
@@ -1188,7 +1188,7 @@ dhcp6_cls_by_type = {  1: "DHCP6_Solicit",
 def _dhcp6_dispatcher(x, *args, **kargs):
     cls = conf.raw_layer
     if len(x) >= 2:
-        cls = get_cls(dhcp6_cls_by_type.get(ord(x[0]), "Raw"), conf.raw_layer)
+        cls = get_cls(dhcp6_cls_by_type.get(orb(x[0]), "Raw"), conf.raw_layer)
     return cls(x, *args, **kargs)
 
 bind_bottom_up(UDP, _dhcp6_dispatcher, { "dport": 547 } )
diff --git a/scapy/layers/dns.py b/scapy/layers/dns.py
index a009486e..cc6604ec 100644
--- a/scapy/layers/dns.py
+++ b/scapy/layers/dns.py
@@ -42,11 +42,11 @@ class DNSStrField(StrField):
     def getfield(self, pkt, s):
         n = b""
 
-        if ord(s[0]) == 0:
+        if orb(s[0]) == 0:
           return s[1:], "."
 
         while True:
-            l = ord(s[0])
+            l = orb(s[0])
             s = s[1:]
             if not l:
                 break
@@ -89,7 +89,7 @@ def DNSgetstr(s,p):
         if p >= len(s):
             warning("DNS RR prematured end (ofs=%i, len=%i)"%(p,len(s)))
             break
-        l = ord(s[p])
+        l = orb(s[p])
         p += 1
         if l & 0xc0:
             if not q:
@@ -97,7 +97,7 @@ def DNSgetstr(s,p):
             if p >= len(s):
                 warning("DNS incomplete jump token at (ofs=%i)" % p)
                 break
-            p = ((l & 0x3f) << 8) + ord(s[p]) - 12
+            p = ((l & 0x3f) << 8) + orb(s[p]) - 12
             if p in jpath:
                 warning("DNS decompression loop detected")
                 break
@@ -205,7 +205,7 @@ class RDataField(StrLenField):
                 s = inet_aton(s)
         elif pkt.type in [2, 3, 4, 5, 12]: # NS, MD, MF, CNAME, PTR
             s = b"".join(chr(len(x)) + x for x in s.split('.'))
-            if ord(s[-1]):
+            if orb(s[-1]):
                 s += b"\x00"
         elif pkt.type == 16: # TXT
             if s:
diff --git a/scapy/layers/eap.py b/scapy/layers/eap.py
index 85a89e0f..ae55d3ba 100644
--- a/scapy/layers/eap.py
+++ b/scapy/layers/eap.py
@@ -81,7 +81,7 @@ class EAPOL(Packet):
         return s[:l], s[l:]
 
     def hashret(self):
-        return chr(self.type) + self.payload.hashret()
+        return chb(self.type) + self.payload.hashret()
 
     def answers(self, other):
         if isinstance(other, EAPOL):
@@ -284,7 +284,7 @@ class EAP(Packet):
     def post_build(self, p, pay):
         if self.len is None:
             l = len(p) + len(pay)
-            p = p[:2] + chr((l >> 8) & 0xff) + chr(l & 0xff) + p[4:]
+            p = p[:2] + chb((l >> 8) & 0xff) + chb(l & 0xff) + p[4:]
         return p + pay
 
 
@@ -466,7 +466,7 @@ class MKAParamSet(Packet):
 
         cls = conf.raw_layer
         if _pkt is not None:
-            ptype = struct.unpack("!B", _pkt[0])[0]
+            ptype = orb(_pkt[0])
             return globals().get(_param_set_cls.get(ptype), conf.raw_layer)
 
         return cls
diff --git a/scapy/layers/inet.py b/scapy/layers/inet.py
index 83fa3bf3..ac9ec729 100644
--- a/scapy/layers/inet.py
+++ b/scapy/layers/inet.py
@@ -109,7 +109,7 @@ class IPOption(Packet):
     @classmethod
     def dispatch_hook(cls, pkt=None, *args, **kargs):
         if pkt:
-            opt = ord(pkt[0])&0x1f
+            opt = orb(pkt[0])&0x1f
             if opt in cls.registered_ip_options:
                 return cls.registered_ip_options[opt]
         return cls
@@ -262,7 +262,7 @@ class TCPOptionsField(StrField):
     def m2i(self, pkt, x):
         opt = []
         while x:
-            onum = ord(x[0])
+            onum = orb(x[0])
             if onum == 0:
                 opt.append(("EOL",None))
                 x=x[1:]
@@ -271,7 +271,7 @@ class TCPOptionsField(StrField):
                 opt.append(("NOP",None))
                 x=x[1:]
                 continue
-            olen = ord(x[1])
+            olen = orb(x[1])
             if olen < 2:
                 warning("Malformed TCP option (announced length is %i)" % olen)
                 olen = 2
@@ -525,7 +525,7 @@ class TCP(Packet):
         dataofs = self.dataofs
         if dataofs is None:
             dataofs = 5+((len(self.get_field("options").i2m(self,self.options))+3)//4)
-            p = p[:12]+chb((dataofs << 4) | ord(p[12])&0x0f)+p[13:]
+            p = p[:12]+chb((dataofs << 4) | orb(p[12])&0x0f)+p[13:]
         if self.chksum is None:
             if isinstance(self.underlayer, IP):
                 ck = in4_chksum(socket.IPPROTO_TCP, self.underlayer, p)
diff --git a/scapy/layers/inet6.py b/scapy/layers/inet6.py
index d7c3dd88..1b74c4d0 100644
--- a/scapy/layers/inet6.py
+++ b/scapy/layers/inet6.py
@@ -387,15 +387,15 @@ class _IPv6GuessPayload:
     name = "Dummy class that implements guess_payload_class() for IPv6"
     def default_payload_class(self,p):
         if self.nh == 58: # ICMPv6
-            t = ord(p[0])
+            t = orb(p[0])
             if len(p) > 2 and (t == 139 or t == 140): # Node Info Query
                 return _niquery_guesser(p)
             if len(p) >= icmp6typesminhdrlen.get(t, float("inf")): # Other ICMPv6 messages
                 return get_cls(icmp6typescls.get(t,"Raw"), "Raw")
             return Raw
         elif self.nh == 135 and len(p) > 3: # Mobile IPv6
-            return _mip6_mhtype2cls.get(ord(p[2]), MIP6MH_Generic)
-        elif self.nh == 43 and ord(p[2]) == 4:  # Segment Routing header
+            return _mip6_mhtype2cls.get(orb(p[2]), MIP6MH_Generic)
+        elif self.nh == 43 and orb(p[2]) == 4:  # Segment Routing header
             return IPv6ExtHdrSegmentRouting
         return get_cls(ipv6nhcls.get(self.nh, "Raw"), "Raw")
 
@@ -871,7 +871,7 @@ class _HopByHopOptionsField(PacketListField):
                 if c <= 0:
                     break
                 c -= 1
-            o = ord(x[0]) # Option type
+            o = orb(x[0]) # Option type
             cls = self.cls
             if o in _hbhoptcls:
                 cls = _hbhoptcls[o]
@@ -1007,7 +1007,7 @@ class IPv6ExtHdrSegmentRoutingTLV(Packet):
     @classmethod
     def dispatch_hook(cls, pkt=None, *args, **kargs):
         if pkt:
-            tmp_type = ord(pkt[0])
+            tmp_type = orb(pkt[0])
             return cls.registered_sr_tlv.get(tmp_type, cls)
         return cls
 
@@ -1657,7 +1657,7 @@ class _ICMPv6NDGuessPayload:
     name = "Dummy ND class that implements guess_payload_class()"
     def guess_payload_class(self,p):
         if len(p) > 1:
-            return get_cls(icmp6ndoptscls.get(ord(p[0]),"Raw"), "Raw") # s/Raw/ICMPv6NDOptUnknown/g ?
+            return get_cls(icmp6ndoptscls.get(orb(p[0]),"Raw"), "Raw") # s/Raw/ICMPv6NDOptUnknown/g ?
 
 
 # Beginning of ICMPv6 Neighbor Discovery Options.
@@ -1918,7 +1918,7 @@ class DomainNameListField(StrLenField):
             # Get a name until \x00 is reached
             cur = []
             while x and x[0] != b'\x00':
-                l = ord(x[0])
+                l = orb(x[0])
                 cur.append(x[1:l+1])
                 x = x[l+1:]
             if self.padded:
@@ -1938,7 +1938,7 @@ class DomainNameListField(StrLenField):
                 return z
             return z+b'\x00'
         # Build the encode names
-        tmp = [[chb(len(z)) + z for z in y.split('.')] for y in x]
+        tmp = [[chb(len(z)) + z.encode("utf8") for z in y.split('.')] for y in x]
         ret_string  = b"".join(conditionalTrailingDot(b"".join(x)) for x in tmp)
 
         # In padded mode, add some \x00 bytes
@@ -2198,14 +2198,14 @@ def dnsrepr2names(x):
     res = []
     cur = ""
     while x:
-        l = ord(x[0])
+        l = orb(x[0])
         x = x[1:]
         if l == 0:
             if cur and cur[-1] == '.':
                 cur = cur[:-1]
             res.append(cur)
             cur = ""
-            if x and ord(x[0]) == 0: # single component
+            if x and orb(x[0]) == 0: # single component
                 x = x[1:]
             continue
         if l & 0xc0: # XXX TODO : work on that -- arno
@@ -2256,7 +2256,7 @@ class NIQueryDataField(StrField):
             res = []
             weird = None
             while val:
-                l = ord(val[0])
+                l = orb(val[0])
                 val = val[1:]
                 if l == 0:
                     if (len(res) > 1 and val): # fqdn with data behind
@@ -2520,7 +2520,7 @@ class ICMPv6NIReplyUnknown(ICMPv6NIReplyNOOP):
 
 def _niquery_guesser(p):
     cls = conf.raw_layer
-    type = ord(p[0])
+    type = orb(p[0])
     if type == 139: # Node Info Query specific stuff
         if len(p) > 6:
             qtype, = struct.unpack("!H", p[4:6])
@@ -2529,7 +2529,7 @@ def _niquery_guesser(p):
                     3: ICMPv6NIQueryIPv6,
                     4: ICMPv6NIQueryIPv4 }.get(qtype, conf.raw_layer)
     elif type == 140: # Node Info Reply specific stuff
-        code = ord(p[1])
+        code = orb(p[1])
         if code == 0:
             if len(p) > 6:
                 qtype, = struct.unpack("!H", p[4:6])
@@ -2861,7 +2861,7 @@ class _MobilityHeader(Packet):
         l = self.len
         if self.len is None:
             l = (len(p)-8)//8
-        p = p[0] + struct.pack("B", l) + p[2:]
+        p = chb(p[0]) + struct.pack("B", l) + chb(p[2:])
         if self.cksum is None:
             cksum = in6_chksum(135, self.underlayer, p)
         else:
@@ -2899,7 +2899,7 @@ class _MobilityOptionsField(PacketListField):
     def m2i(self, pkt, x):
         opt = []
         while x:
-            o = ord(x[0]) # Option type
+            o = orb(x[0]) # Option type
             cls = self.cls
             if o in moboptcls:
                 cls = moboptcls[o]
diff --git a/scapy/layers/l2.py b/scapy/layers/l2.py
index d461c041..3b6d70a4 100644
--- a/scapy/layers/l2.py
+++ b/scapy/layers/l2.py
@@ -59,7 +59,7 @@ conf.netcache.new_cache("arp_cache", 120) # cache entries expire after 120s
 @conf.commands.register
 def getmacbyip(ip, chainCC=0):
     """Return MAC address corresponding to a given IP address"""
-    if isinstance(ip,Net):
+    if isinstance(ip, Net):
         ip = iter(ip).next()
     ip = inet_ntoa(inet_aton(ip))
     tmp = [orb(e) for e in inet_aton(ip)]
diff --git a/scapy/layers/llmnr.py b/scapy/layers/llmnr.py
index e4067061..3b879bb2 100644
--- a/scapy/layers/llmnr.py
+++ b/scapy/layers/llmnr.py
@@ -51,7 +51,7 @@ class LLMNRResponse(LLMNRQuery):
 def _llmnr_dispatcher(x, *args, **kargs):
     cls = conf.raw_layer
     if len(x) >= 2:
-        if (ord(x[2]) & 0x80): # Response
+        if (orb(x[2]) & 0x80): # Response
             cls = LLMNRResponse
         else:                  # Query
             cls = LLMNRQuery
diff --git a/scapy/layers/lltd.py b/scapy/layers/lltd.py
index 560c8eec..3ef01d2a 100644
--- a/scapy/layers/lltd.py
+++ b/scapy/layers/lltd.py
@@ -10,7 +10,6 @@ https://msdn.microsoft.com/en-us/library/cc233983.aspx
 """
 
 from __future__ import absolute_import
-import struct
 from array import array
 
 from scapy.fields import BitField, FlagsField, ByteField, ByteEnumField, \
@@ -215,7 +214,7 @@ class LLTDQueryResp(Packet):
         if self.descs_count is None:
             # descs_count should be a FieldLenField but has an
             # unsupported format (14 bits)
-            flags = ord(pkt[0]) & 0xc0
+            flags = orb(pkt[0]) & 0xc0
             count = len(self.descs_list)
             pkt = chb(flags + (count >> 8)) + chb(count % 256) + pkt[2:]
         return pkt + pay
@@ -257,7 +256,7 @@ class LLTDQueryLargeTlvResp(Packet):
         if self.len is None:
             # len should be a FieldLenField but has an unsupported
             # format (14 bits)
-            flags = ord(pkt[0]) & 0xc0
+            flags = orb(pkt[0]) & 0xc0
             length = len(self.value)
             pkt = chb(flags + (length >> 8)) + chb(length % 256) + pkt[2:]
         return pkt + pay
@@ -297,7 +296,7 @@ class LLTDAttribute(Packet):
     @classmethod
     def dispatch_hook(cls, _pkt=None, *_, **kargs):
         if _pkt:
-            cmd = struct.unpack("B", _pkt[0])[0]
+            cmd = orb(_pkt[0])
         elif "type" in kargs:
             cmd = kargs["type"]
             if isinstance(cmd, six.string_types):
diff --git a/scapy/layers/ppp.py b/scapy/layers/ppp.py
index 6a16d3d7..ad9d4d87 100644
--- a/scapy/layers/ppp.py
+++ b/scapy/layers/ppp.py
@@ -208,7 +208,7 @@ class PPP(Packet):
     fields_desc = [ ShortEnumField("proto", 0x0021, _PPP_proto) ]
     @classmethod
     def dispatch_hook(cls, _pkt=None, *args, **kargs):
-        if _pkt and ord(_pkt[0]) == 0xff:
+        if _pkt and orb(_pkt[0]) == 0xff:
             cls = HDLC
         return cls
 
@@ -324,7 +324,7 @@ class PPP_ECP_Option(Packet):
     @classmethod
     def dispatch_hook(cls, _pkt=None, *args, **kargs):
         if _pkt:
-            o = ord(_pkt[0])
+            o = orb(_pkt[0])
             return cls.registered_options.get(o, cls)
         return cls
 
@@ -376,7 +376,7 @@ class PPP_LCP(Packet):
     @classmethod
     def dispatch_hook(cls, _pkt = None, *args, **kargs):
         if _pkt:
-            o = ord(_pkt[0])
+            o = orb(_pkt[0])
             if o in [1, 2, 3, 4]:
                 return PPP_LCP_Configure
             elif o in [5,6]:
@@ -423,7 +423,7 @@ class PPP_LCP_Option(Packet):
     @classmethod
     def dispatch_hook(cls, _pkt=None, *args, **kargs):
         if _pkt:
-            o = ord(_pkt[0])
+            o = orb(_pkt[0])
             return cls.registered_options.get(o, cls)
         return cls
 
@@ -578,7 +578,7 @@ class PPP_PAP(Packet):
     def dispatch_hook(cls, _pkt=None, *_, **kargs):
         code = None
         if _pkt:
-            code = ord(_pkt[0])
+            code = orb(_pkt[0])
         elif "code" in kargs:
             code = kargs["code"]
             if isinstance(code, basestring):
@@ -651,7 +651,7 @@ class PPP_CHAP(Packet):
     def dispatch_hook(cls, _pkt=None, *_, **kargs):
         code = None
         if _pkt:
-            code = ord(_pkt[0])
+            code = orb(_pkt[0])
         elif "code" in kargs:
             code = kargs["code"]
             if isinstance(code, basestring):
diff --git a/scapy/layers/radius.py b/scapy/layers/radius.py
index 5b6e0baf..544fa2d0 100644
--- a/scapy/layers/radius.py
+++ b/scapy/layers/radius.py
@@ -264,7 +264,7 @@ class RadiusAttribute(Packet):
         """
 
         if _pkt:
-            attr_type = ord(_pkt[0])
+            attr_type = orb(_pkt[0])
             return cls.registered_attributes.get(attr_type, cls)
         return cls
 
@@ -1092,7 +1092,7 @@ class _RADIUSAttrPacketListField(PacketListField):
             remain, ret = s[:length], s[length:]
 
         while remain:
-            attr_len = struct.unpack("!B", remain[1])[0]
+            attr_len = orb(remain[1])
             current = remain[:attr_len]
             remain = remain[attr_len:]
             packet = self.m2i(pkt, current)
diff --git a/scapy/layers/sctp.py b/scapy/layers/sctp.py
index 253a2948..0c29ca79 100644
--- a/scapy/layers/sctp.py
+++ b/scapy/layers/sctp.py
@@ -93,7 +93,7 @@ crc32c_table = [
 def crc32c(buf):
     crc = 0xffffffff
     for c in buf:
-        crc = (crc>>8) ^ crc32c_table[(crc^(ord(c))) & 0xFF]
+        crc = (crc>>8) ^ crc32c_table[(crc^(orb(c))) & 0xFF]
     crc = (~crc) & 0xffffffff
     # reverse endianness
     return struct.unpack(">I",struct.pack("<I", crc))[0]
@@ -107,8 +107,8 @@ def update_adler32(adler, buf):
     print s1,s2
 
     for c in buf:
-        print ord(c)
-        s1 = (s1 + ord(c)) % BASE
+        print orb(c)
+        s1 = (s1 + orb(c)) % BASE
         s2 = (s2 + s1) % BASE
         print s1,s2
     return (s2 << 16) + s1
@@ -216,7 +216,7 @@ class _SCTPChunkGuessPayload:
         if len(p) < 4:
             return conf.padding_layer
         else:
-            t = ord(p[0])
+            t = orb(p[0])
             return globals().get(sctpchunktypescls.get(t, "Raw"), conf.raw_layer)
 
 
@@ -248,7 +248,7 @@ class ChunkParamField(PacketListField):
     def m2i(self, p, m):
         cls = conf.raw_layer
         if len(m) >= 4:
-            t = ord(m[0]) * 256 + ord(m[1])
+            t = orb(m[0]) * 256 + orb(m[1])
             cls = globals().get(sctpchunkparamtypescls.get(t, "Raw"), conf.raw_layer)
         return cls(m)
 
diff --git a/scapy/layers/tls/session.py b/scapy/layers/tls/session.py
index 93623d8d..393073c6 100644
--- a/scapy/layers/tls/session.py
+++ b/scapy/layers/tls/session.py
@@ -971,7 +971,7 @@ class _tls_sessions(object):
                 if len(sid) > 12:
                     sid = sid[:11] + "..."
                 res.append((src, dst, sid))
-        colwidth = [max([len(y) for y in x]) for x in zip(*res)]
+        colwidth = (max([len(y) for y in x]) for x in zip(*res))
         fmt = "  ".join(map(lambda x: "%%-%ds"%x, colwidth))
         return "\n".join(map(lambda x: fmt % x, res))
 
diff --git a/scapy/layers/vrrp.py b/scapy/layers/vrrp.py
index 249a00cb..8c9027cc 100644
--- a/scapy/layers/vrrp.py
+++ b/scapy/layers/vrrp.py
@@ -42,7 +42,7 @@ class VRRP(Packet):
     @classmethod
     def dispatch_hook(cls, _pkt=None, *args, **kargs):
         if _pkt and len(_pkt) >= 9:
-            ver_n_type = ord(_pkt[0])
+            ver_n_type = orb(_pkt[0])
             if ver_n_type >= 48 and ver_n_type <= 57: # Version == 3
                 return VRRPv3
         return VRRP
@@ -72,13 +72,13 @@ class VRRPv3(Packet):
             else:
                 warning("No IP(v6) layer to compute checksum on VRRP. Leaving null")
                 ck = 0
-            p = p[:6]+chr(ck>>8)+chr(ck&0xff)+p[8:]
+            p = p[:6]+chb(ck>>8)+chb(ck&0xff)+p[8:]
         return p
 
     @classmethod
     def dispatch_hook(cls, _pkt=None, *args, **kargs):
         if _pkt and len(_pkt) >= 16:
-            ver_n_type = ord(_pkt[0])
+            ver_n_type = orb(_pkt[0])
             if ver_n_type < 48 or ver_n_type > 57: # Version != 3
                 return VRRP
         return VRRPv3
diff --git a/scapy/route6.py b/scapy/route6.py
index 38da8193..eff1d9b3 100644
--- a/scapy/route6.py
+++ b/scapy/route6.py
@@ -223,7 +223,7 @@ class Route6:
             return (scapy.consts.LOOPBACK_INTERFACE, "::", "::")
 
         # Sort with longest prefix first
-        pathes.sort(reverse=True)
+        pathes.sort(reverse=True, key=lambda x: x[0])
 
         best_plen = pathes[0][0]
         pathes = [x for x in pathes if x[0] == best_plen]
diff --git a/scapy/utils.py b/scapy/utils.py
index 498abc45..a9ebe7cd 100644
--- a/scapy/utils.py
+++ b/scapy/utils.py
@@ -42,21 +42,21 @@ def get_temp_file(keep=False, autoext=""):
 def sane_color(x):
     r=""
     for i in x:
-        j = ord(i)
+        j = orb(i)
         if (j < 32) or (j >= 127):
             r=r+conf.color_theme.not_printable(".")
         else:
-            r=r+i
+            r=r+chr(j)
     return r
 
 def sane(x):
     r=""
     for i in x:
-        j = ord(i)
+        j = orb(i)
         if (j < 32) or (j >= 127):
             r=r+"."
         else:
-            r=r+i
+            r=r+chr(j)
     return r
 
 def lhex(x):
@@ -950,7 +950,7 @@ class RawPcapNgReader(RawPcapReader):
             # 4.2. - Interface Description Block
             # http://xml2rfc.tools.ietf.org/cgi-bin/xml2rfc.cgi?url=https://raw.githubusercontent.com/pcapng/pcapng/master/draft-tuexen-opsawg-pcapng.xml&modeAsFormat=html/ascii&type=ascii#rfc.section.4.2
             if code == 9 and length == 1 and len(options) >= 5:
-                tsresol = ord(options[4])
+                tsresol = orb(options[4])
                 tsresol = (2 if tsresol & 128 else 10) ** (tsresol & 127)
             if code == 0:
                 if length != 0:
diff --git a/scapy/utils6.py b/scapy/utils6.py
index 2fecdf11..51be5b5d 100644
--- a/scapy/utils6.py
+++ b/scapy/utils6.py
@@ -228,7 +228,7 @@ def in6_ifaceidtomac(ifaceid): # TODO: finish commenting function behavior
     first = struct.pack("B", ((first & 0xFD) | ulbit))
     oui = first + ifaceid[1:3]
     end = ifaceid[5:]
-    l = ["%.02x" % struct.unpack('B', raw(x))[0] for x in list(oui + end)]
+    l = ["%.02x" % orb(x) for x in list(oui + end)]
     return ":".join(l)
 
 def in6_addrtomac(addr):
@@ -766,7 +766,7 @@ def in6_get_common_plen(a, b):
     tmpA = inet_pton(socket.AF_INET6, a)
     tmpB = inet_pton(socket.AF_INET6, b)
     for i in range(16):
-        mbits = matching_bits(ord(tmpA[i]), ord(tmpB[i]))
+        mbits = matching_bits(orb(tmpA[i]), orb(tmpB[i]))
         if mbits != 8:
             return 8*i + mbits
     return 128
diff --git a/test/regression.uts b/test/regression.uts
index 14740c92..02860a17 100644
--- a/test/regression.uts
+++ b/test/regression.uts
@@ -671,9 +671,9 @@ x=SNMP(b'0y\x02\x01\x00\x04\x06public\xa2l\x02\x01)\x02\x01\x00\x02\x01\x000a0!\
 x.show()
 assert(x.community==b"public" and x.version == 0)
 assert(x.PDU.id == 41 and len(x.PDU.varbindlist) == 3)
-assert(x.PDU.varbindlist[0].oid == b"1.3.6.1.4.1.253.8.64.4.2.1.7.10.14130104")
+assert(x.PDU.varbindlist[0].oid == "1.3.6.1.4.1.253.8.64.4.2.1.7.10.14130104")
 assert(x.PDU.varbindlist[0].value == b"172.31.19.2")
-assert(x.PDU.varbindlist[2].oid == b"1.3.6.1.4.1.253.8.64.4.2.1.5.10.14130400")
+assert(x.PDU.varbindlist[2].oid == "1.3.6.1.4.1.253.8.64.4.2.1.5.10.14130400")
 assert(x.PDU.varbindlist[2].value == 1)
 
 
@@ -843,7 +843,7 @@ dns_ans.show2()
 dns_ans[DNS].an.show()
 dns_ans2 = IP(raw(dns_ans))
 DNS in dns_ans2
-assert(raw(dns_ans2) == str(dns_ans))
+assert(raw(dns_ans2) == raw(dns_ans))
 dns_ans2.qd.qname = "www.secdev.org."
 * We need to recalculate these values
 del(dns_ans2[IP].len)
@@ -1232,7 +1232,7 @@ class ATMT9(Automaton):
         self.send(Raw("ENU"))
     @ATMT.ioevent(BEGIN, name="loop")
     def received_sth(self, fd):
-        self.res += fd.recv().load
+        self.res += plain_str(fd.recv().load)
         raise self.END()
     @ATMT.state(final=1)
     def END(self):
@@ -1252,7 +1252,7 @@ a.BEGIN.intercepts()
 while True:
     try:
         x = a.run()
-    except Automaton.InterceptionPoint,p:
+    except Automaton.InterceptionPoint as p:
         a.accept_packet(Raw(p.packet.load.lower()), wait=False)
     else:
         break
@@ -1343,7 +1343,7 @@ raw(p)
 assert(_ == b'\x80!\x01\x00\x00\x16\x81\x06\x01\x02\x03\x04\x83\x06\x05\x06\x07\x08\x84\x06\t\n\x0b\x0c')
 PPP(_)
 q=_
-assert(raw(p) == str(q))
+assert(raw(p) == raw(q))
 assert(PPP(raw(q))==q)
 PPP()/PPP_IPCP(options=[PPP_IPCP_Option_DNS1(data="1.2.3.4"),PPP_IPCP_Option_DNS2(data="5.6.7.8"),PPP_IPCP_Option(type=123,data="ABCDEFG"),PPP_IPCP_Option_NBNS2(data="9.10.11.12")])
 p=_
@@ -1741,7 +1741,7 @@ raw(ICMPv6EchoRequest(code=0xff, cksum=0x1111, id=0x2222, seq=0x3333, data="this
 
 = ICMPv6EchoRequest - Basic dissection
 a=ICMPv6EchoRequest(b'\x80\x00\x00\x00\x00\x00\x00\x00')
-a.type == 128 and a.code == 0 and a.cksum == 0 and a.id == 0 and a.seq == 0 and a.data == b""
+a.type == 128 and a.code == 0 and a.cksum == 0 and a.id == 0 and a.seq == 0 and a.data == ""
 
 = ICMPv6EchoRequest - Dissection with specific values 
 a=ICMPv6EchoRequest(b'\x80\xff\x11\x11""33thisissomerawing')
@@ -1767,7 +1767,7 @@ raw(ICMPv6EchoReply(code=0xff, cksum=0x1111, id=0x2222, seq=0x3333, data="thisis
 
 = ICMPv6EchoReply - Basic dissection
 a=ICMPv6EchoReply(b'\x80\x00\x00\x00\x00\x00\x00\x00')
-a.type == 128 and a.code == 0 and a.cksum == 0 and a.id == 0 and a.seq == 0 and a.data == b""
+a.type == 128 and a.code == 0 and a.cksum == 0 and a.id == 0 and a.seq == 0 and a.data == ""
 
 = ICMPv6EchoReply - Dissection with specific values 
 a=ICMPv6EchoReply(b'\x80\xff\x11\x11""33thisissomerawing')
@@ -1866,7 +1866,7 @@ raw(HBHOptUnknown()) == b'\x01\x00'
 
 = HBHOptUnknown - Basic Dissection 
 a=HBHOptUnknown(b'\x01\x00')
-a.otype == 0x01 and a.optlen == 0 and a.optdata == b""
+a.otype == 0x01 and a.optlen == 0 and a.optdata == ""
 
 = HBHOptUnknown - Automatic optlen computation
 raw(HBHOptUnknown(optdata="B"*10)) == b'\x01\nBBBBBBBBBB'
@@ -1902,7 +1902,7 @@ raw(PadN(optdata="B"*10)) == b'\x01\nBBBBBBBBBB'
 
 = PadN - Basic Dissection
 a=PadN(b'\x01\x00')
-a.otype == 1 and a.optlen == 0 and a.optdata == b''
+a.otype == 1 and a.optlen == 0 and a.optdata == ""
 
 = PadN - Dissection with specific values 
 a=PadN(b'\x01\x0cBBBBBBBBBB')
@@ -2131,7 +2131,7 @@ a.type == 0 and a.len == 2
 
 = ICMPv6NDOptUnknown - Dissection with specific values 
 a=ICMPv6NDOptUnknown(b'\x00\x04somerawing')
-a.type == 0 and a.len==4 and a.data == b"so" and isinstance(a.payload, Raw) and a.payload.load == "merawing"
+a.type == 0 and a.len==4 and a.data == b"so" and isinstance(a.payload, Raw) and a.payload.load == b"merawing"
 
 
 ############
@@ -2552,7 +2552,7 @@ raw(ICMPv6NIQueryNOOP(nonce=b"\x00"*8)) == b'\x8b\x01\x00\x00\x00\x00\x00\x00\x0
 
 = ICMPv6NIQueryNOOP - Basic Dissection
 a = ICMPv6NIQueryNOOP(b'\x8b\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
-a.type == 139 and a.code == 1 and a.cksum == 0 and a.qtype == 0 and a.unused == 0 and a.flags == 0 and a.nonce == b"\x00"*8 and a.data == b""
+a.type == 139 and a.code == 1 and a.cksum == 0 and a.qtype == 0 and a.unused == 0 and a.flags == 0 and a.nonce == b"\x00"*8 and a.data == ""
 
 
 ############
@@ -4071,14 +4071,14 @@ raw(DHCP6OptRemoteID()) == b'\x00%\x00\x04\x00\x00\x00\x00'
 
 = DHCP6OptRemoteID - Basic Dissection
 a = DHCP6OptRemoteID(b'\x00%\x00\x04\x00\x00\x00\x00')
-a.optcode == 37 and a.optlen == 4 and a.enterprisenum == 0 and a.remoteid == ""
+a.optcode == 37 and a.optlen == 4 and a.enterprisenum == 0 and a.remoteid == b""
 
 = DHCP6OptRemoteID - Instantiation with specific values 
 raw(DHCP6OptRemoteID(enterprisenum=0xeeeeeeee, remoteid="someid")) == b'\x00%\x00\n\xee\xee\xee\xeesomeid'
 
 = DHCP6OptRemoteID - Dissection with specific values
 a = DHCP6OptRemoteID(b'\x00%\x00\n\xee\xee\xee\xeesomeid')
-a.optcode == 37 and a.optlen == 10 and a.enterprisenum == 0xeeeeeeee and a.remoteid == "someid"
+a.optcode == 37 and a.optlen == 10 and a.enterprisenum == 0xeeeeeeee and a.remoteid == b"someid"
 
 
 ############
@@ -4090,14 +4090,14 @@ raw(DHCP6OptSubscriberID()) == b'\x00&\x00\x00'
 
 = DHCP6OptSubscriberID - Basic Dissection
 a = DHCP6OptSubscriberID(b'\x00&\x00\x00')
-a.optcode == 38 and a.optlen == 0 and a.subscriberid == ""
+a.optcode == 38 and a.optlen == 0 and a.subscriberid == b""
 
 = DHCP6OptSubscriberID - Instantiation with specific values
 raw(DHCP6OptSubscriberID(subscriberid="someid")) == b'\x00&\x00\x06someid'
 
 = DHCP6OptSubscriberID - Dissection with specific values
 a = DHCP6OptSubscriberID(b'\x00&\x00\x06someid')
-a.optcode == 38 and a.optlen == 6 and a.subscriberid == "someid"
+a.optcode == 38 and a.optlen == 6 and a.subscriberid == b"someid"
 
 
 ############
@@ -4112,7 +4112,7 @@ a = DHCP6OptClientFQDN(b"\x00'\x00\x01\x00")
 a.optcode == 39 and a.optlen == 1 and a.res == 0 and a.flags == 0 and a.fqdn == ""
 
 = DHCP6OptClientFQDN - Instantiation with various flags combinations
-raw(DHCP6OptClientFQDN(flags="S")) == b"\x00'\x00\x01\x01" and str(DHCP6OptClientFQDN(flags="O")) == b"\x00'\x00\x01\x02" and str(DHCP6OptClientFQDN(flags="N")) == b"\x00'\x00\x01\x04" and str(DHCP6OptClientFQDN(flags="SON")) == b"\x00'\x00\x01\x07" and str(DHCP6OptClientFQDN(flags="ON")) == b"\x00'\x00\x01\x06"
+raw(DHCP6OptClientFQDN(flags="S")) == b"\x00'\x00\x01\x01" and raw(DHCP6OptClientFQDN(flags="O")) == b"\x00'\x00\x01\x02" and raw(DHCP6OptClientFQDN(flags="N")) == b"\x00'\x00\x01\x04" and raw(DHCP6OptClientFQDN(flags="SON")) == b"\x00'\x00\x01\x07" and raw(DHCP6OptClientFQDN(flags="ON")) == b"\x00'\x00\x01\x06"
 
 = DHCP6OptClientFQDN - Instantiation with one fqdn 
 raw(DHCP6OptClientFQDN(fqdn="toto.example.org")) == b"\x00'\x00\x12\x00\x04toto\x07example\x03org"
@@ -5516,7 +5516,7 @@ eol = TCP(b"\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00`\x02 \x00\x00\x00\x00\
 eol[TCP].options[0][0] == "EOL" and eol[TCP].options[0][1] == None
 
 = TCP options: malformed - build
-raw(TCP(options=[('unknown', '')])) == str(TCP())
+raw(TCP(options=[('unknown', '')])) == raw(TCP())
 
 = TCP options: malformed - dissection
 raw(TCP(b"\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00`\x02 \x00\x00\x00\x00\x00\x03\x00\x00\x00")) == b"\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00`\x02 \x00\x00\x00\x00\x00\x03\x00\x00\x00"
@@ -6409,7 +6409,7 @@ s = b"!\x0b\x06\xea\x00\x00\x00\x00\x00\x00\xf2\xc1\x7f\x7f\x01\x00\xdb9\xe8\xa2
 p = NTP(s)
 assert(isinstance(p, NTPHeader))
 assert(p[NTPAuthenticator].key_id == 1)
-assert(p[NTPAuthenticator].dgst.encode("hex") == 'ad79f3a1e5fcd032d26a1e27c3c1b60e')
+assert(bytes_hex(p[NTPAuthenticator].dgst) == 'ad79f3a1e5fcd032d26a1e27c3c1b60e')
 
 
 = NTPHeader - KoD
@@ -6523,7 +6523,7 @@ assert(p.status_word.peer_event_code == 1)
 assert(p.association_id == 64655)
 assert(p.offset == 0)
 assert(p.count == 468)
-assert(p.data.load == 'srcadr=192.168.122.1, srcport=123, dstadr=192.168.122.100, dstport=123,\r\nleap=3, stratum=16, precision=-24, rootdelay=0.000, rootdisp=0.000,\r\nrefid=INIT, reftime=0x00000000.00000000, rec=0x00000000.00000000,\r\nreach=0x0, unreach=5, hmode=1, pmode=0, hpoll=6, ppoll=10, headway=62,\r\nflash=0x1200, keyid=1, offset=0.000, delay=0.000, dispersion=15937.500,\r\njitter=0.000, xleave=0.240,\r\nfiltdelay= 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00,\r\nfiltoffset= 0.00 0.00 0.00 0.00 ')
+assert(p.data.load == b'srcadr=192.168.122.1, srcport=123, dstadr=192.168.122.100, dstport=123,\r\nleap=3, stratum=16, precision=-24, rootdelay=0.000, rootdisp=0.000,\r\nrefid=INIT, reftime=0x00000000.00000000, rec=0x00000000.00000000,\r\nreach=0x0, unreach=5, hmode=1, pmode=0, hpoll=6, ppoll=10, headway=62,\r\nflash=0x1200, keyid=1, offset=0.000, delay=0.000, dispersion=15937.500,\r\njitter=0.000, xleave=0.240,\r\nfiltdelay= 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00,\r\nfiltoffset= 0.00 0.00 0.00 0.00 ')
  
 
 = NTP Control (mode 6) - CTL_OP_READVAR (3) - reponse (2nd packet)
@@ -6556,7 +6556,7 @@ assert(p.more == 0)
 assert(p.op_code == 2)
 assert(len(p.data.load) == 12)
 assert(p.authenticator.key_id == 1)
-assert(p.authenticator.dgst.encode("hex") == '3dc23bc7edb9555339d68908c8afa612')
+assert(bytes_hex(p.authenticator.dgst) == '3dc23bc7edb9555339d68908c8afa612')
 
 
 = NTP Control (mode 6) - CTL_OP_READVAR (5) - response
@@ -6571,7 +6571,7 @@ assert(p.more == 0)
 assert(p.op_code == 2)
 assert(len(p.data.load) == 0)
 assert(p.authenticator.key_id == 1)
-assert(p.authenticator.dgst.encode("hex") == '97280249dba07338ed722860db4a580a')
+assert(bytes_hex(p.authenticator.dgst) == '97280249dba07338ed722860db4a580a')
 
 
 = NTP Control (mode 6) - CTL_OP_WRITEVAR (1) - request
@@ -6586,7 +6586,7 @@ assert(p.more == 0)
 assert(p.op_code == 3)
 assert(len(p.data.load) == 12)
 assert(p.authenticator.key_id == 1)
-assert(p.authenticator.dgst.encode("hex") == 'aff10cb4c9946dfc4d90094aa170944a')
+assert(bytes_hex(p.authenticator.dgst) == 'aff10cb4c9946dfc4d90094aa170944a')
 
 
 = NTP Control (mode 6) - CTL_OP_WRITEVAR (2) - response
@@ -6604,7 +6604,7 @@ assert(isinstance(p.status_word, NTPErrorStatusPacket))
 assert(p.status_word.error_code == 5)
 assert(len(p.data.load) == 0)
 assert(p.authenticator.key_id == 1)
-assert(p.authenticator.dgst.encode("hex") == '807a80fbafc470679853a8e57865811c')
+assert(bytes_hex(p.authenticator.dgst) == '807a80fbafc470679853a8e57865811c')
 
 
 = NTP Control (mode 6) - CTL_OP_CONFIGURE (1) - request
@@ -6618,9 +6618,9 @@ assert(p.err == 0)
 assert(p.more == 0)
 assert(p.op_code == 8)
 assert(p.count == 12)
-assert(p.data.load == 'controlkey 1')
+assert(p.data.load == b'controlkey 1')
 assert(p.authenticator.key_id == 1)
-assert(p.authenticator.dgst.encode("hex") == 'eaa7aca81b6a9cdb58e1530d36fbefa4')
+assert(bytes_hex(p.authenticator.dgst) == 'eaa7aca81b6a9cdb58e1530d36fbefa4')
 
 
 = NTP Control (mode 6) - CTL_OP_CONFIGURE (2) - response
@@ -6636,7 +6636,7 @@ assert(p.op_code == 8)
 assert(p.count == 18)
 assert(p.data.load == b'Config Succeeded\r\n\x00\x00')
 assert(p.authenticator.key_id == 1)
-assert(p.authenticator.dgst.encode("hex") == 'bfa6d85ff96d1e326c293caceec2a539')
+assert(bytes_hex(p.authenticator.dgst) == 'bfa6d85ff96d1e326c293caceec2a539')
 
 
 = NTP Control (mode 6) - CTL_OP_SAVECONFIG (1) - request
@@ -6652,7 +6652,7 @@ assert(p.op_code == 9)
 assert(p.count == 15)
 assert(p.data.load == b'ntp.test.2.conf\x00')
 assert(p.authenticator.key_id == 1)
-assert(p.authenticator.dgst.encode("hex") == 'c9fb8abe3c605ffa36d218c3b7648923')
+assert(bytes_hex(p.authenticator.dgst) == 'c9fb8abe3c605ffa36d218c3b7648923')
 
 
 = NTP Control (mode 6) - CTL_OP_SAVECONFIG (2) - response
@@ -6668,7 +6668,7 @@ assert(p.op_code == 9)
 assert(p.count == 42)
 assert(p.data.load == b"Configuration saved to 'ntp.test.2.conf'\r\n\x00\x00")
 assert(p.authenticator.key_id == 1)
-assert(p.authenticator.dgst.encode("hex") == '32c2ba59c533fe28f550e5a0860295d9')
+assert(bytes_hex(p.authenticator.dgst) == '32c2ba59c533fe28f550e5a0860295d9')
 
 
 = NTP Control (mode 6) - CTL_OP_REQ_NONCE (1) - request
@@ -6695,7 +6695,7 @@ assert(p.response == 1)
 assert(p.err == 0)
 assert(p.more == 0)
 assert(p.op_code == 12)
-assert(p.data.load == 'nonce=db4186a2e1d9022472e24bc9\r\n')
+assert(p.data.load == b'nonce=db4186a2e1d9022472e24bc9\r\n')
 assert(p.authenticator == '')
 
 
@@ -6709,7 +6709,7 @@ assert(p.response == 0)
 assert(p.err == 0)
 assert(p.op_code == 10)
 assert(p.count == 40)
-assert(p.data.load == 'nonce=db4186a2e1d9022472e24bc9, frags=32')
+assert(p.data.load == b'nonce=db4186a2e1d9022472e24bc9, frags=32')
 assert(p.authenticator == '')
 
 = NTP Control (mode 6) - CTL_OP_READ_MRU (2) - response
@@ -7053,7 +7053,7 @@ assert(p.req_data[0].minpoll == 6)
 assert(p.req_data[0].maxpoll == 10)
 assert(hasattr(p, 'authenticator'))
 assert(p.authenticator.key_id == 1)
-assert(p.authenticator.dgst.encode("hex") == '5abafe011c720564a114b129e976448d')
+assert(bytes_hex(p.authenticator.dgst) == '5abafe011c720564a114b129e976448d')
 
 
 = NTP Private (mode 7) - REQ_CONFIG (2) - response
@@ -7088,7 +7088,7 @@ assert(p.req_data[0].peeraddr == "192.168.122.107")
 assert(p.req_data[0].v6_flag == 0)
 assert(hasattr(p, 'authenticator'))
 assert(p.authenticator.key_id == 1)
-assert(p.authenticator.dgst.encode("hex") == '1d4d3bfe5a7e5d5ae34561929a45d825')
+assert(bytes_hex(p.authenticator.dgst) == '1d4d3bfe5a7e5d5ae34561929a45d825')
 
 
 = NTP Private (mode 7) - REQ_UNCONFIG (2) - response
@@ -7123,7 +7123,7 @@ assert(p.req_data[0].addr == "192.168.122.105")
 assert(p.req_data[0].mask == "255.255.255.255")
 assert(hasattr(p, 'authenticator'))
 assert(p.authenticator.key_id == 1)
-assert(p.authenticator.dgst.encode("hex") == '3e3db7305470eeaee1ad3462efe380c8')
+assert(bytes_hex(p.authenticator.dgst) == '3e3db7305470eeaee1ad3462efe380c8')
 
 
 = NTP Private (mode 7) - REQ_RESSUBFLAGS (1) - request
@@ -7143,7 +7143,7 @@ assert(p.req_data[0].addr == "192.168.122.105")
 assert(p.req_data[0].mask == "255.255.255.255")
 assert(hasattr(p, 'authenticator'))
 assert(p.authenticator.key_id == 1)
-assert(p.authenticator.dgst.encode("hex") == '3e650ddfdb1e3168d0ca294c076b900a')
+assert(bytes_hex(p.authenticator.dgst) == '3e650ddfdb1e3168d0ca294c076b900a')
 
 
 = NTP Private (mode 7) - REQ_RESET_PEER (1) - request
@@ -7206,7 +7206,7 @@ assert(isinstance(p.req_data[0], NTPConfTrap))
 assert(p.req_data[0].trap_address == '192.0.2.3')
 assert(hasattr(p, 'authenticator'))
 assert(p.authenticator.key_id == 1)
-assert(p.authenticator.dgst.encode("hex") == '6224b8494d2ea631d085498fa7278992')
+assert(bytes_hex(p.authenticator.dgst) == '6224b8494d2ea631d085498fa7278992')
 
 
 = NTP Private (mode 7) - REQ_ADD_TRAP (2) - response
@@ -7241,7 +7241,7 @@ assert(isinstance(p.req_data[0], NTPConfTrap))
 assert(p.req_data[0].trap_address == '192.0.2.3')
 assert(hasattr(p, 'authenticator'))
 assert(p.authenticator.key_id == 1)
-assert(p.authenticator.dgst.encode("hex") == 'a55f569eb87144921b1c3e5aad5d2a89')
+assert(bytes_hex(p.authenticator.dgst) == 'a55f569eb87144921b1c3e5aad5d2a89')
 
 
 = NTP Private (mode 7) - REQ_CLR_TRAP (2) - response
@@ -7351,7 +7351,7 @@ assert(p.nb_items == 0)
 assert(p.data_item_size == 0)
 assert(hasattr(p, 'authenticator'))
 assert(p.authenticator.key_id == 1)
-assert(p.authenticator.dgst.encode("hex") == '8bfb9075a86164e887cabf96d29ddd49')
+assert(bytes_hex(p.authenticator.dgst) == '8bfb9075a86164e887cabf96d29ddd49')
 
 
 = NTP Private (mode 7) - REQ_IF_STATS (2) - response
@@ -7370,7 +7370,7 @@ assert(p.data_item_size == 136)
 assert(isinstance(p.data[0], NTPInfoIfStatsIPv6))
 assert(p.data[0].unaddr == "::1")
 assert(p.data[0].unmask == "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
-assert(p.data[0].ifname.startswith("lo"))
+assert(p.data[0].ifname.startswith(b"lo"))
 
 
 = NTP Private (mode 7) - REQ_IF_STATS (3) - response
@@ -7389,7 +7389,7 @@ assert(p.data_item_size == 136)
 assert(isinstance(p.data[0], NTPInfoIfStatsIPv4))
 assert(p.data[0].unaddr == "192.168.122.101")
 assert(p.data[0].unmask == "255.255.255.0")
-assert(p.data[0].ifname.startswith("eth1"))
+assert(p.data[0].ifname.startswith(b"eth1"))
 
 
 = NTP Private (mode 7) - REQ_IF_RELOAD (1) - request
@@ -7406,7 +7406,7 @@ assert(p.nb_items == 0)
 assert(p.data_item_size == 0)
 assert(hasattr(p, 'authenticator'))
 assert(p.authenticator.key_id == 1)
-assert(p.authenticator.dgst.encode("hex") == 'fb3e962ae74ff78f6568d4074cc008cb')
+assert(bytes_hex(p.authenticator.dgst) == 'fb3e962ae74ff78f6568d4074cc008cb')
 
 
 = NTP Private (mode 7) - REQ_IF_RELOAD (2) - response
@@ -7425,7 +7425,7 @@ assert(p.data_item_size == 136)
 assert(isinstance(p.data[0], NTPInfoIfStatsIPv4))
 assert(p.data[0].unaddr == "127.0.0.1")
 assert(p.data[0].unmask == "255.0.0.0")
-assert(p.data[0].ifname.startswith("lo"))
+assert(p.data[0].ifname.startswith(b"lo"))
 
 
 ############
@@ -7686,11 +7686,11 @@ VRRP in p and p[VRRP].chksum == 0x7afd
 = VRRP - chksums
 # VRRPv3
 p = Ether(src="00:00:5e:00:02:02",dst="01:00:5e:00:00:12")/IP(src="20.0.0.3", dst="224.0.0.18",ttl=255)/VRRPv3(priority=254,vrid=2,version=3,adv=1,addrlist=["20.0.1.2","20.0.1.3"])
-a = Ether(str(p))
+a = Ether(raw(p))
 assert a[VRRPv3].chksum == 0xb25e
 # VRRPv1
 p = Ether(src="00:00:5e:00:02:02",dst="01:00:5e:00:00:12")/IP(src="20.0.0.3", dst="224.0.0.18",ttl=255)/VRRP(priority=254,vrid=2,version=1,adv=1,addrlist=["20.0.1.2","20.0.1.3"])
-b = Ether(str(p))
+b = Ether(raw(p))
 assert b[VRRP].chksum == 0xc6f4
 
 ############
@@ -8621,7 +8621,7 @@ Dot11 in p and p.addr3 == "00:00:00:00:00:00"
 p.mysummary() == '802.11 Management 0 00:00:00:00:00:00 > 00:00:00:00:00:00'
 
 = Dot11QoS - build
-s = str(Dot11(type=2, subtype=8)/Dot11QoS(TID=4))
+s = raw(Dot11(type=2, subtype=8)/Dot11QoS(TID=4))
 s == b'\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00'
 
 = Dot11QoS - dissection
@@ -8687,7 +8687,7 @@ assert a.src == '00:00:00:00:00:00'
 
 import tempfile
 fd, fname = tempfile.mkstemp()
-os.write(fd, "-- MIB test\nscapy       OBJECT IDENTIFIER ::= {test 2807}\n")
+os.write(fd, b"-- MIB test\nscapy       OBJECT IDENTIFIER ::= {test 2807}\n")
 os.close(fd)
 
 load_mib(fname)
-- 
GitLab