# Buggy code
def __init__(
    self,
    iface=None,
    type=ETH_P_ALL,
    promisc=None,
    filter=None,
    nofilter=0,
    monitor=False,
):
    self.fd_flags = None
    self.assigned_interface = None

    # SuperSocket mandatory variables
    if promisc is None:
        self.promisc = conf.sniff_promisc
    else:
        self.promisc = promisc

    self.iface = network_name(iface or conf.iface)

    # Get the BPF handle
    (self.ins, self.dev_bpf) = get_dev_bpf()
    self.outs = self.ins

    # Set the BPF buffer length
    try:
        fcntl.ioctl(self.ins, BIOCSBLEN, struct.pack("I", BPF_BUFFER_LENGTH))  # noqa: E501
    except IOError:
        raise Scapy_Exception("BIOCSBLEN failed on /dev/bpf%i" % self.dev_bpf)

    # Assign the network interface to the BPF handle
    try:
        fcntl.ioctl(self.ins, BIOCSETIF, struct.pack("16s16x", self.iface.encode()))  # noqa: E501
    except IOError:
        raise Scapy_Exception("BIOCSETIF failed on %s" % self.iface)
    self.assigned_interface = self.iface

    # Set the interface into promiscuous
    if self.promisc:
        self.set_promisc(1)

    # Set the interface to monitor mode
    # Note: - trick from libpcap/pcap-bpf.c - monitor_mode()
    #       - it only works on OS X 10.5 and later
    if DARWIN and monitor:
        dlt_radiotap = struct.pack("I", DLT_IEEE802_11_RADIO)
        try:
            fcntl.ioctl(self.ins, BIOCSDLT, dlt_radiotap)
        except IOError:
            raise Scapy_Exception("Can't set %s into monitor mode!" % self.iface)

    # Don't block on read
    try:
        fcntl.ioctl(self.ins, BIOCIMMEDIATE, struct.pack("I", 1))
    except IOError:
        raise Scapy_Exception("BIOCIMMEDIATE failed on /dev/bpf%i" % self.dev_bpf)

    # Scapy will provide the link layer source address
    # Otherwise, it is written by the kernel
    try:
        fcntl.ioctl(self.ins, BIOCSHDRCMPLT, struct.pack("i", 1))
    except IOError:
        raise Scapy_Exception("BIOCSHDRCMPLT failed on /dev/bpf%i" % self.dev_bpf)

    # Configure the BPF filter
    if not nofilter:
        if conf.except_filter:
            if filter:
                filter = "(%s) and not (%s)" % (filter, conf.except_filter)
            else:
                filter = "not (%s)" % conf.except_filter
        if filter is not None:
            try:
                attach_filter(self.ins, filter, self.iface)
            except ImportError as ex:
                warning("Cannot set filter: %s" % ex)

    # Set the guessed packet class
    self.guessed_cls = self.guess_cls()


# Traceback (AttributeError)
from scapy.config import conf
from scapy.sendrecv import AsyncSniffer
conf.L2socket()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/bdraco/Library/Python/3.8/lib/python/site-packages/scapy/arch/bpf/supersocket.py", line 242, in __init__
super(L2bpfListenSocket, self).__init__(*args, **kwargs)
File "/Users/bdraco/Library/Python/3.8/lib/python/site-packages/scapy/arch/bpf/supersocket.py", line 62, in __init__
(self.ins, self.dev_bpf) = get_dev_bpf()
File "/Users/bdraco/Library/Python/3.8/lib/python/site-packages/scapy/arch/bpf/core.py", line 114, in get_dev_bpf
raise Scapy_Exception("No /dev/bpf handle is available !")
scapy.error.Scapy_Exception: No /dev/bpf handle is available !
^D
Exception ignored in: <function _L2bpfSocket.__del__ at 0x110de31f0>
Traceback (most recent call last):
File "/Users/bdraco/Library/Python/3.8/lib/python/site-packages/scapy/arch/bpf/supersocket.py", line 139, in __del__
self.close()
File "/Users/bdraco/Library/Python/3.8/lib/python/site-packages/scapy/arch/bpf/supersocket.py", line 211, in close
if not self.closed and self.ins is not None:
AttributeError: 'L2bpfSocket' object has no attribute 'ins'

# Fixed code
def __init__(
    self,
    iface=None,
    type=ETH_P_ALL,
    promisc=None,
    filter=None,
    nofilter=0,
    monitor=False,
):
    self.fd_flags = None
    self.assigned_interface = None

    # SuperSocket mandatory variables
    if promisc is None:
        self.promisc = conf.sniff_promisc
    else:
        self.promisc = promisc

    self.iface = network_name(iface or conf.iface)

    # Get the BPF handle
    self.ins = None
    (self.ins, self.dev_bpf) = get_dev_bpf()
    self.outs = self.ins

    # Set the BPF buffer length
    try:
        fcntl.ioctl(self.ins, BIOCSBLEN, struct.pack("I", BPF_BUFFER_LENGTH))  # noqa: E501
    except IOError:
        raise Scapy_Exception("BIOCSBLEN failed on /dev/bpf%i" % self.dev_bpf)

    # Assign the network interface to the BPF handle
    try:
        fcntl.ioctl(self.ins, BIOCSETIF, struct.pack("16s16x", self.iface.encode()))  # noqa: E501
    except IOError:
        raise Scapy_Exception("BIOCSETIF failed on %s" % self.iface)
    self.assigned_interface = self.iface

    # Set the interface into promiscuous
    if self.promisc:
        self.set_promisc(1)

    # Set the interface to monitor mode
    # Note: - trick from libpcap/pcap-bpf.c - monitor_mode()
    #       - it only works on OS X 10.5 and later
    if DARWIN and monitor:
        dlt_radiotap = struct.pack("I", DLT_IEEE802_11_RADIO)
        try:
            fcntl.ioctl(self.ins, BIOCSDLT, dlt_radiotap)
        except IOError:
            raise Scapy_Exception("Can't set %s into monitor mode!" % self.iface)

    # Don't block on read
    try:
        fcntl.ioctl(self.ins, BIOCIMMEDIATE, struct.pack("I", 1))
    except IOError:
        raise Scapy_Exception("BIOCIMMEDIATE failed on /dev/bpf%i" % self.dev_bpf)

    # Scapy will provide the link layer source address
    # Otherwise, it is written by the kernel
    try:
        fcntl.ioctl(self.ins, BIOCSHDRCMPLT, struct.pack("i", 1))
    except IOError:
        raise Scapy_Exception("BIOCSHDRCMPLT failed on /dev/bpf%i" % self.dev_bpf)

    # Configure the BPF filter
    if not nofilter:
        if conf.except_filter:
            if filter:
                filter = "(%s) and not (%s)" % (filter, conf.except_filter)
            else:
                filter = "not (%s)" % conf.except_filter
        if filter is not None:
            try:
                attach_filter(self.ins, filter, self.iface)
            except ImportError as ex:
                warning("Cannot set filter: %s" % ex)

    # Set the guessed packet class
    self.guessed_cls = self.guess_cls()