# Buggy code
def post_build(self, p, pay):
    if self.domnamelen is None:
        domnamelen = len(self.domname.strip(b"\x00"))
        p = p[:3] + chr(domnamelen & 0xFF) + p[4:]

    p += pay

    return p


# Traceback (TypeError)
root@ubuntu:/workspace/_prototype/rtg-avatar# python
Python 3.7.5 (default, Nov  7 2019, 10:50:52)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
from scapy.all import *
from scapy.contrib import *
pkt=CDPv2_HDR(vers=2, ttl=180, msg='123')
len(pkt)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 522, in __len__
return len(self.__bytes__())
File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 487, in __bytes__
return self.build()
File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 607, in build
p = self.do_build()
File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 594, in do_build
return self.post_build(pkt, pay)
File "/usr/local/lib/python3.7/dist-packages/scapy/contrib/cdp.py", line 371, in post_build
cksum = checksum(self._check_len(p))
File "/usr/local/lib/python3.7/dist-packages/scapy/contrib/cdp.py", line 361, in _check_len
if last_chr <= b'\x80':
TypeError: '<=' not supported between instances of 'int' and 'bytes'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 522, in __len__
return len(self.__bytes__())
File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 487, in __bytes__
return self.build()
File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 607, in build
p = self.do_build()
File "/usr/local/lib/python3.7/dist-packages/scapy/packet.py", line 594, in do_build
return self.post_build(pkt, pay)
File "/usr/local/lib/python3.7/dist-packages/scapy/contrib/cdp.py", line 371, in post_build
cksum = checksum(self._check_len(p))
File "/usr/local/lib/python3.7/dist-packages/scapy/contrib/cdp.py", line 361, in _check_len
if last_chr <= b'\x80':
TypeError: '<=' not supported between instances of 'int' and 'bytes'


# Fixed code
def post_build(self, p, pay):
    if self.domnamelen is None:
        domnamelen = len(self.domname.strip(b"\x00"))
        p = p[:3] + chb(domnamelen & 0xFF) + p[4:]

    p += pay

    return p