# Buggy code
def compile_filter(filter_exp, iface=None, linktype=None, promisc=False):
    """Asks libpcap to parse the filter, then build the matching
    BPF bytecode.

    :param iface: if provided, use the interface to compile
    :param linktype: if provided, use the linktype to compile
    """
    try:
        from scapy.libs.winpcapy import (
            PCAP_ERRBUF_SIZE,
            pcap_open_live,
            pcap_compile,
            pcap_compile_nopcap,
            pcap_close,
        )
        from scapy.libs.structures import bpf_program
    except ImportError:
        raise Scapy_Exception("libpcap is not available. Cannot compile filter !")
    root = WINDOWS or (os.geteuid() == 0)
    from ctypes import create_string_buffer

    bpf = bpf_program()
    bpf_filter = create_string_buffer(filter_exp.encode("utf8"))
    if not linktype:
        # Try to guess linktype to avoid root
        if not iface:
            if not conf.iface:
                raise Scapy_Exception("Please provide an interface or linktype!")
            if WINDOWS:
                iface = conf.iface.pcap_name
            else:
                iface = conf.iface
        # Try to guess linktype to avoid requiring root
        try:
            arphd = get_if_raw_hwaddr(iface)[0]
            linktype = ARPHRD_TO_DLT.get(arphd)
        except Exception:
            # Failed to use linktype: use the interface
            if not root:
                raise Scapy_Exception("Please provide a valid interface or linktype!")
    if linktype is not None:
        ret = pcap_compile_nopcap(MTU, linktype, ctypes.byref(bpf), bpf_filter, 0, -1)
    elif iface:
        if not root:
            raise OSError("Compiling using an interface requires root.")
        err = create_string_buffer(PCAP_ERRBUF_SIZE)
        iface = create_string_buffer(iface.encode("utf8"))
        pcap = pcap_open_live(iface, MTU, promisc, 0, err)
        ret = pcap_compile(pcap, ctypes.byref(bpf), bpf_filter, 0, -1)
        pcap_close(pcap)
    if ret == -1:
        raise Scapy_Exception(
            "Failed to compile filter expression %s (%s)" % (filter_exp, ret)
        )
    if conf.use_pypy:
        # XXX PyPy has a broken behavior.
        # https://bitbucket.org/pypy/pypy/issues/3114
        return struct.pack("HL", bpf.bf_len, ctypes.addressof(bpf.bf_insns.contents))
    return bpf


# Traceback (AttributeError)
a = Ether(dst='64:A2:F9:A9:2E:A9')/ARP(pdst='192.168.178.0/24')
a.show()

AttributeError
Traceback (most recent call last)<ipython-input-18-97d3136b2c17> in <module>
----> 1 a.show()

/netdisk/home/gpotter/github/scapy/scapy/packet.py in show(self, dump, indent, lvl, label_lvl)
1251         :return: return a hierarchical view if dump, else print it
1252         """
-> 1253         return self._show_or_dump(dump, indent, lvl, label_lvl)
1254
1255     def show2(self, dump=False, indent=3, lvl="", label_lvl=""):

/netdisk/home/gpotter/github/scapy/scapy/packet.py in _show_or_dump(self, dump, indent, lvl, label_lvl, first_call)
1225                                          ncol(f.name),
1226                                          ct.punct("="),)
-> 1227                 reprval = f.i2repr(self, fvalue)
1228                 if isinstance(reprval, str):
1229                     reprval = reprval.replace("\n", "\n" + " " * (len(label_lvl) +  # noqa: E501

/netdisk/home/gpotter/github/scapy/scapy/fields.py in i2repr(self, pkt, x)
513
514     def i2repr(self, pkt, x):
--> 515         x = self.i2h(pkt, x)
516         if self in conf.resolve:
517             x = conf.manufdb._resolve_MAC(x)

/netdisk/home/gpotter/github/scapy/scapy/layers/l2.py in i2h(self, pkt, x)
140     def i2h(self, pkt, x):
141         if x is None:
--> 142             iff = self.getif(pkt)
143             if iff is None:
144                 iff = conf.iface

/netdisk/home/gpotter/github/scapy/scapy/layers/l2.py in <lambda>(pkt)
136     def __init__(self, name, getif=None):
137         MACField.__init__(self, name, None)
--> 138         self.getif = (lambda pkt: pkt.route()[0]) if getif is None else getif
139
140     def i2h(self, pkt, x):

/netdisk/home/gpotter/github/scapy/scapy/packet.py in route(self)
1175
1176     def route(self):
-> 1177         return self.payload.route()
1178
1179     def fragment(self, *args, **kargs):

/netdisk/home/gpotter/github/scapy/scapy/layers/l2.py in route(self)
411     def route(self):
412         fld, dst = self.getfield_and_val("pdst")--> 413         fld, dst = fld._find_fld_pkt_val(self, dst)
414         if isinstance(dst, Gen):
415             dst = next(iter(dst))

/netdisk/home/gpotter/github/scapy/scapy/fields.py in _find_fld_pkt_val(self, pkt, val)
324         # Default ? (in this case, let's make sure it's up-do-date)
325         dflts_pkt = pkt.default_fields
--> 326         if val == dflts_pkt[self.name] and self.name not in pkt.fields:
327             dflts_pkt[self.name] = fld.default
328             val = fld.default

/netdisk/home/gpotter/github/scapy/scapy/base_classes.py in __eq__(self, other)
131             p2 = other.parsed
132         else:
--> 133             p2, nm2 = self._parse_net(other)
134         return self.parsed == p2
135

/netdisk/home/gpotter/github/scapy/scapy/base_classes.py in _parse_net(cls, net)
97     @classmethod
98     def _parse_net(cls, net):
---> 99         tmp = net.split('/') + ["32"]
100         if not cls.ip_regex.match(net):
101             tmp[0] = socket.gethostbyname(tmp[0])

AttributeError: 'NoneType' object has no attribute 'split'

# Fixed code
def compile_filter(filter_exp, iface=None, linktype=None, promisc=False):
    """Asks libpcap to parse the filter, then build the matching
    BPF bytecode.

    :param iface: if provided, use the interface to compile
    :param linktype: if provided, use the linktype to compile
    """
    try:
        from scapy.libs.winpcapy import (
            PCAP_ERRBUF_SIZE,
            pcap_open_live,
            pcap_compile,
            pcap_compile_nopcap,
            pcap_close,
        )
        from scapy.libs.structures import bpf_program
    except ImportError:
        raise Scapy_Exception("libpcap is not available. Cannot compile filter !")
    root = WINDOWS or (os.geteuid() == 0)
    from ctypes import create_string_buffer

    bpf = bpf_program()
    bpf_filter = create_string_buffer(filter_exp.encode("utf8"))
    if not linktype:
        # Try to guess linktype to avoid root
        if not iface:
            if not conf.iface:
                raise Scapy_Exception("Please provide an interface or linktype!")
            if WINDOWS:
                iface = conf.iface.pcap_name
            else:
                iface = conf.iface
        # Try to guess linktype to avoid requiring root
        try:
            arphd = get_if_raw_hwaddr(iface)[0]
            linktype = ARPHRD_TO_DLT.get(arphd)
        except Exception:
            # Failed to use linktype: use the interface
            if not root:
                raise Scapy_Exception("Please provide a valid interface or linktype!")
    if linktype is not None:
        ret = pcap_compile_nopcap(MTU, linktype, ctypes.byref(bpf), bpf_filter, 0, -1)
    elif iface:
        if not root:
            raise OSError("Compiling using an interface requires root.")
        err = create_string_buffer(PCAP_ERRBUF_SIZE)
        iface = create_string_buffer(iface.encode("utf8"))
        pcap = pcap_open_live(iface, MTU, promisc, 0, err)
        ret = pcap_compile(pcap, ctypes.byref(bpf), bpf_filter, 0, -1)
        pcap_close(pcap)
    if ret == -1:
        raise Scapy_Exception(
            "Failed to compile filter expression %s (%s)" % (filter_exp, ret)
        )
    if conf.use_pypy and sys.pypy_version_info <= (7, 3, 0):
        # PyPy < 7.3.0 has a broken behavior
        # https://bitbucket.org/pypy/pypy/issues/3114
        return struct.pack("HL", bpf.bf_len, ctypes.addressof(bpf.bf_insns.contents))
    return bpf