We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Interface's name isn't necessary to be ended with a digit
Remove the step to convert to integer as it doesn't affect the result.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scapy/arch/bpf/core.py`
Content:
```
1 # Guillaume Valadon <guillaume@valadon.net>
2 
3 """
4 Scapy *BSD native support - core
5 """
6 
7 from __future__ import absolute_import
8 from scapy.config import conf
9 from scapy.error import Scapy_Exception, warning
10 from scapy.data import ARPHDR_LOOPBACK, ARPHDR_ETHER
11 from scapy.arch.common import get_if, compile_filter
12 from scapy.consts import LOOPBACK_NAME
13 
14 from scapy.arch.bpf.consts import BIOCSETF, SIOCGIFFLAGS, BIOCSETIF
15 
16 import os
17 import socket
18 import fcntl
19 import struct
20 
21 from ctypes import cdll, cast, pointer
22 from ctypes import c_int, c_ulong, c_char_p
23 from ctypes.util import find_library
24 from scapy.modules.six.moves import range
25 
26 
27 # ctypes definitions
28 
29 LIBC = cdll.LoadLibrary(find_library("libc"))
30 LIBC.ioctl.argtypes = [c_int, c_ulong, c_char_p]
31 LIBC.ioctl.restype = c_int
32 
33 
34 # Addresses manipulation functions
35 
36 def get_if_raw_addr(ifname):
37     """Returns the IPv4 address configured on 'ifname', packed with inet_pton."""  # noqa: E501
38 
39     # Get ifconfig output
40     try:
41         fd = os.popen("%s %s" % (conf.prog.ifconfig, ifname))
42     except OSError as msg:
43         warning("Failed to execute ifconfig: (%s)", msg)
44         return b"\0\0\0\0"
45 
46     # Get IPv4 addresses
47     addresses = [l for l in fd if l.find("inet ") >= 0]
48     if not addresses:
49         warning("No IPv4 address found on %s !", ifname)
50         return b"\0\0\0\0"
51 
52     # Pack the first address
53     address = addresses[0].split(' ')[1]
54     if '/' in address:  # NetBSD 8.0
55         address = address.split("/")[0]
56     return socket.inet_pton(socket.AF_INET, address)
57 
58 
59 def get_if_raw_hwaddr(ifname):
60     """Returns the packed MAC address configured on 'ifname'."""
61 
62     NULL_MAC_ADDRESS = b'\x00' * 6
63 
64     # Handle the loopback interface separately
65     if ifname == LOOPBACK_NAME:
66         return (ARPHDR_LOOPBACK, NULL_MAC_ADDRESS)
67 
68     # Get ifconfig output
69     try:
70         fd = os.popen("%s %s" % (conf.prog.ifconfig, ifname))
71     except OSError as msg:
72         raise Scapy_Exception("Failed to execute ifconfig: (%s)" % msg)
73 
74     # Get MAC addresses
75     addresses = [l for l in fd.readlines() if l.find("ether") >= 0 or
76                  l.find("lladdr") >= 0 or
77                  l.find("address") >= 0]
78     if not addresses:
79         raise Scapy_Exception("No MAC address found on %s !" % ifname)
80 
81     # Pack and return the MAC address
82     mac = addresses[0].split(' ')[1]
83     mac = [chr(int(b, 16)) for b in mac.split(':')]
84     return (ARPHDR_ETHER, ''.join(mac))
85 
86 
87 # BPF specific functions
88 
89 def get_dev_bpf():
90     """Returns an opened BPF file object"""
91 
92     # Get the first available BPF handle
93     for bpf in range(256):
94         try:
95             fd = os.open("/dev/bpf%i" % bpf, os.O_RDWR)
96             return (fd, bpf)
97         except OSError:
98             continue
99 
100     raise Scapy_Exception("No /dev/bpf handle is available !")
101 
102 
103 def attach_filter(fd, bpf_filter, iface):
104     """Attach a BPF filter to the BPF file descriptor"""
105     bp = compile_filter(bpf_filter, iface)
106     # Assign the BPF program to the interface
107     ret = LIBC.ioctl(c_int(fd), BIOCSETF, cast(pointer(bp), c_char_p))
108     if ret < 0:
109         raise Scapy_Exception("Can't attach the BPF filter !")
110 
111 
112 # Interface manipulation functions
113 
114 def get_if_list():
115     """Returns a list containing all network interfaces."""
116 
117     # Get ifconfig output
118     try:
119         fd = os.popen("%s -a" % conf.prog.ifconfig)
120     except OSError as msg:
121         raise Scapy_Exception("Failed to execute ifconfig: (%s)" % msg)
122 
123     # Get interfaces
124     interfaces = [line[:line.find(':')] for line in fd.readlines()
125                   if ": flags" in line.lower()]
126     return interfaces
127 
128 
129 def get_working_ifaces():
130     """
131     Returns an ordered list of interfaces that could be used with BPF.
132     Note: the order mimics pcap_findalldevs() behavior
133     """
134 
135     # Only root is allowed to perform the following ioctl() call
136     if os.getuid() != 0:
137         return []
138 
139     # Test all network interfaces
140     interfaces = []
141     for ifname in get_if_list():
142 
143         # Unlike pcap_findalldevs(), we do not care of loopback interfaces.
144         if ifname == LOOPBACK_NAME:
145             continue
146 
147         # Get interface flags
148         try:
149             result = get_if(ifname, SIOCGIFFLAGS)
150         except IOError:
151             warning("ioctl(SIOCGIFFLAGS) failed on %s !", ifname)
152             continue
153 
154         # Convert flags
155         ifflags = struct.unpack("16xH14x", result)[0]
156         if ifflags & 0x1:  # IFF_UP
157 
158             # Get a BPF handle
159             fd, _ = get_dev_bpf()
160             if fd is None:
161                 raise Scapy_Exception("No /dev/bpf are available !")
162 
163             # Check if the interface can be used
164             try:
165                 fcntl.ioctl(fd, BIOCSETIF, struct.pack("16s16x", ifname.encode()))  # noqa: E501
166                 interfaces.append((ifname, int(ifname[-1])))
167             except IOError:
168                 pass
169 
170             # Close the file descriptor
171             os.close(fd)
172 
173     # Sort to mimic pcap_findalldevs() order
174     interfaces.sort(key=lambda elt: elt[1])
175 
176     return interfaces
177 
178 
179 def get_working_if():
180     """Returns the first interface than can be used with BPF"""
181 
182     ifaces = get_working_ifaces()
183     if not ifaces:
184         # A better interface will be selected later using the routing table
185         return LOOPBACK_NAME
186     return ifaces[0][0]
187
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scapy/arch/bpf/core.py b/scapy/arch/bpf/core.py
--- a/scapy/arch/bpf/core.py
+++ b/scapy/arch/bpf/core.py
@@ -5,22 +5,22 @@
 """
 
 from __future__ import absolute_import
-from scapy.config import conf
-from scapy.error import Scapy_Exception, warning
-from scapy.data import ARPHDR_LOOPBACK, ARPHDR_ETHER
-from scapy.arch.common import get_if, compile_filter
-from scapy.consts import LOOPBACK_NAME
-
-from scapy.arch.bpf.consts import BIOCSETF, SIOCGIFFLAGS, BIOCSETIF
 
+from ctypes import cdll, cast, pointer
+from ctypes import c_int, c_ulong, c_char_p
+from ctypes.util import find_library
+import fcntl
 import os
+import re
 import socket
-import fcntl
 import struct
 
-from ctypes import cdll, cast, pointer
-from ctypes import c_int, c_ulong, c_char_p
-from ctypes.util import find_library
+from scapy.arch.bpf.consts import BIOCSETF, SIOCGIFFLAGS, BIOCSETIF
+from scapy.arch.common import get_if, compile_filter
+from scapy.config import conf
+from scapy.consts import LOOPBACK_NAME
+from scapy.data import ARPHDR_LOOPBACK, ARPHDR_ETHER
+from scapy.error import Scapy_Exception, warning
 from scapy.modules.six.moves import range
 
 
@@ -126,6 +126,9 @@
     return interfaces
 
 
+_IFNUM = re.compile("([0-9]*)([ab]?)$")
+
+
 def get_working_ifaces():
     """
     Returns an ordered list of interfaces that could be used with BPF.
@@ -156,24 +159,27 @@
         if ifflags & 0x1:  # IFF_UP
 
             # Get a BPF handle
-            fd, _ = get_dev_bpf()
+            fd = get_dev_bpf()[0]
             if fd is None:
                 raise Scapy_Exception("No /dev/bpf are available !")
 
             # Check if the interface can be used
             try:
-                fcntl.ioctl(fd, BIOCSETIF, struct.pack("16s16x", ifname.encode()))  # noqa: E501
-                interfaces.append((ifname, int(ifname[-1])))
+                fcntl.ioctl(fd, BIOCSETIF, struct.pack("16s16x",
+                                                       ifname.encode()))
             except IOError:
                 pass
-
-            # Close the file descriptor
-            os.close(fd)
+            else:
+                ifnum, ifab = _IFNUM.search(ifname).groups()
+                interfaces.append((ifname, int(ifnum) if ifnum else -1, ifab))
+            finally:
+                # Close the file descriptor
+                os.close(fd)
 
     # Sort to mimic pcap_findalldevs() order
-    interfaces.sort(key=lambda elt: elt[1])
+    interfaces.sort(key=lambda elt: (elt[1], elt[2], elt[0]))
 
-    return interfaces
+    return [iface[0] for iface in interfaces]
 
 
 def get_working_if():
@@ -183,4 +189,4 @@
     if not ifaces:
         # A better interface will be selected later using the routing table
         return LOOPBACK_NAME
-    return ifaces[0][0]
+    return ifaces[0]

{"golden_diff": "diff --git a/scapy/arch/bpf/core.py b/scapy/arch/bpf/core.py\n--- a/scapy/arch/bpf/core.py\n+++ b/scapy/arch/bpf/core.py\n@@ -5,22 +5,22 @@\n \"\"\"\n \n from __future__ import absolute_import\n-from scapy.config import conf\n-from scapy.error import Scapy_Exception, warning\n-from scapy.data import ARPHDR_LOOPBACK, ARPHDR_ETHER\n-from scapy.arch.common import get_if, compile_filter\n-from scapy.consts import LOOPBACK_NAME\n-\n-from scapy.arch.bpf.consts import BIOCSETF, SIOCGIFFLAGS, BIOCSETIF\n \n+from ctypes import cdll, cast, pointer\n+from ctypes import c_int, c_ulong, c_char_p\n+from ctypes.util import find_library\n+import fcntl\n import os\n+import re\n import socket\n-import fcntl\n import struct\n \n-from ctypes import cdll, cast, pointer\n-from ctypes import c_int, c_ulong, c_char_p\n-from ctypes.util import find_library\n+from scapy.arch.bpf.consts import BIOCSETF, SIOCGIFFLAGS, BIOCSETIF\n+from scapy.arch.common import get_if, compile_filter\n+from scapy.config import conf\n+from scapy.consts import LOOPBACK_NAME\n+from scapy.data import ARPHDR_LOOPBACK, ARPHDR_ETHER\n+from scapy.error import Scapy_Exception, warning\n from scapy.modules.six.moves import range\n \n \n@@ -126,6 +126,9 @@\n     return interfaces\n \n \n+_IFNUM = re.compile(\"([0-9]*)([ab]?)$\")\n+\n+\n def get_working_ifaces():\n     \"\"\"\n     Returns an ordered list of interfaces that could be used with BPF.\n@@ -156,24 +159,27 @@\n         if ifflags & 0x1:  # IFF_UP\n \n             # Get a BPF handle\n-            fd, _ = get_dev_bpf()\n+            fd = get_dev_bpf()[0]\n             if fd is None:\n                 raise Scapy_Exception(\"No /dev/bpf are available !\")\n \n             # Check if the interface can be used\n             try:\n-                fcntl.ioctl(fd, BIOCSETIF, struct.pack(\"16s16x\", ifname.encode()))  # noqa: E501\n-                interfaces.append((ifname, int(ifname[-1])))\n+                fcntl.ioctl(fd, BIOCSETIF, struct.pack(\"16s16x\",\n+                                                       ifname.encode()))\n             except IOError:\n                 pass\n-\n-            # Close the file descriptor\n-            os.close(fd)\n+            else:\n+                ifnum, ifab = _IFNUM.search(ifname).groups()\n+                interfaces.append((ifname, int(ifnum) if ifnum else -1, ifab))\n+            finally:\n+                # Close the file descriptor\n+                os.close(fd)\n \n     # Sort to mimic pcap_findalldevs() order\n-    interfaces.sort(key=lambda elt: elt[1])\n+    interfaces.sort(key=lambda elt: (elt[1], elt[2], elt[0]))\n \n-    return interfaces\n+    return [iface[0] for iface in interfaces]\n \n \n def get_working_if():\n@@ -183,4 +189,4 @@\n     if not ifaces:\n         # A better interface will be selected later using the routing table\n         return LOOPBACK_NAME\n-    return ifaces[0][0]\n+    return ifaces[0]\n", "issue": "Interface's name isn't necessary to be ended with a digit\nRemove the step to convert to integer as it doesn't affect the result.\n", "before_files": [{"content": "# Guillaume Valadon <guillaume@valadon.net>\n\n\"\"\"\nScapy *BSD native support - core\n\"\"\"\n\nfrom __future__ import absolute_import\nfrom scapy.config import conf\nfrom scapy.error import Scapy_Exception, warning\nfrom scapy.data import ARPHDR_LOOPBACK, ARPHDR_ETHER\nfrom scapy.arch.common import get_if, compile_filter\nfrom scapy.consts import LOOPBACK_NAME\n\nfrom scapy.arch.bpf.consts import BIOCSETF, SIOCGIFFLAGS, BIOCSETIF\n\nimport os\nimport socket\nimport fcntl\nimport struct\n\nfrom ctypes import cdll, cast, pointer\nfrom ctypes import c_int, c_ulong, c_char_p\nfrom ctypes.util import find_library\nfrom scapy.modules.six.moves import range\n\n\n# ctypes definitions\n\nLIBC = cdll.LoadLibrary(find_library(\"libc\"))\nLIBC.ioctl.argtypes = [c_int, c_ulong, c_char_p]\nLIBC.ioctl.restype = c_int\n\n\n# Addresses manipulation functions\n\ndef get_if_raw_addr(ifname):\n    \"\"\"Returns the IPv4 address configured on 'ifname', packed with inet_pton.\"\"\"  # noqa: E501\n\n    # Get ifconfig output\n    try:\n        fd = os.popen(\"%s %s\" % (conf.prog.ifconfig, ifname))\n    except OSError as msg:\n        warning(\"Failed to execute ifconfig: (%s)\", msg)\n        return b\"\\0\\0\\0\\0\"\n\n    # Get IPv4 addresses\n    addresses = [l for l in fd if l.find(\"inet \") >= 0]\n    if not addresses:\n        warning(\"No IPv4 address found on %s !\", ifname)\n        return b\"\\0\\0\\0\\0\"\n\n    # Pack the first address\n    address = addresses[0].split(' ')[1]\n    if '/' in address:  # NetBSD 8.0\n        address = address.split(\"/\")[0]\n    return socket.inet_pton(socket.AF_INET, address)\n\n\ndef get_if_raw_hwaddr(ifname):\n    \"\"\"Returns the packed MAC address configured on 'ifname'.\"\"\"\n\n    NULL_MAC_ADDRESS = b'\\x00' * 6\n\n    # Handle the loopback interface separately\n    if ifname == LOOPBACK_NAME:\n        return (ARPHDR_LOOPBACK, NULL_MAC_ADDRESS)\n\n    # Get ifconfig output\n    try:\n        fd = os.popen(\"%s %s\" % (conf.prog.ifconfig, ifname))\n    except OSError as msg:\n        raise Scapy_Exception(\"Failed to execute ifconfig: (%s)\" % msg)\n\n    # Get MAC addresses\n    addresses = [l for l in fd.readlines() if l.find(\"ether\") >= 0 or\n                 l.find(\"lladdr\") >= 0 or\n                 l.find(\"address\") >= 0]\n    if not addresses:\n        raise Scapy_Exception(\"No MAC address found on %s !\" % ifname)\n\n    # Pack and return the MAC address\n    mac = addresses[0].split(' ')[1]\n    mac = [chr(int(b, 16)) for b in mac.split(':')]\n    return (ARPHDR_ETHER, ''.join(mac))\n\n\n# BPF specific functions\n\ndef get_dev_bpf():\n    \"\"\"Returns an opened BPF file object\"\"\"\n\n    # Get the first available BPF handle\n    for bpf in range(256):\n        try:\n            fd = os.open(\"/dev/bpf%i\" % bpf, os.O_RDWR)\n            return (fd, bpf)\n        except OSError:\n            continue\n\n    raise Scapy_Exception(\"No /dev/bpf handle is available !\")\n\n\ndef attach_filter(fd, bpf_filter, iface):\n    \"\"\"Attach a BPF filter to the BPF file descriptor\"\"\"\n    bp = compile_filter(bpf_filter, iface)\n    # Assign the BPF program to the interface\n    ret = LIBC.ioctl(c_int(fd), BIOCSETF, cast(pointer(bp), c_char_p))\n    if ret < 0:\n        raise Scapy_Exception(\"Can't attach the BPF filter !\")\n\n\n# Interface manipulation functions\n\ndef get_if_list():\n    \"\"\"Returns a list containing all network interfaces.\"\"\"\n\n    # Get ifconfig output\n    try:\n        fd = os.popen(\"%s -a\" % conf.prog.ifconfig)\n    except OSError as msg:\n        raise Scapy_Exception(\"Failed to execute ifconfig: (%s)\" % msg)\n\n    # Get interfaces\n    interfaces = [line[:line.find(':')] for line in fd.readlines()\n                  if \": flags\" in line.lower()]\n    return interfaces\n\n\ndef get_working_ifaces():\n    \"\"\"\n    Returns an ordered list of interfaces that could be used with BPF.\n    Note: the order mimics pcap_findalldevs() behavior\n    \"\"\"\n\n    # Only root is allowed to perform the following ioctl() call\n    if os.getuid() != 0:\n        return []\n\n    # Test all network interfaces\n    interfaces = []\n    for ifname in get_if_list():\n\n        # Unlike pcap_findalldevs(), we do not care of loopback interfaces.\n        if ifname == LOOPBACK_NAME:\n            continue\n\n        # Get interface flags\n        try:\n            result = get_if(ifname, SIOCGIFFLAGS)\n        except IOError:\n            warning(\"ioctl(SIOCGIFFLAGS) failed on %s !\", ifname)\n            continue\n\n        # Convert flags\n        ifflags = struct.unpack(\"16xH14x\", result)[0]\n        if ifflags & 0x1:  # IFF_UP\n\n            # Get a BPF handle\n            fd, _ = get_dev_bpf()\n            if fd is None:\n                raise Scapy_Exception(\"No /dev/bpf are available !\")\n\n            # Check if the interface can be used\n            try:\n                fcntl.ioctl(fd, BIOCSETIF, struct.pack(\"16s16x\", ifname.encode()))  # noqa: E501\n                interfaces.append((ifname, int(ifname[-1])))\n            except IOError:\n                pass\n\n            # Close the file descriptor\n            os.close(fd)\n\n    # Sort to mimic pcap_findalldevs() order\n    interfaces.sort(key=lambda elt: elt[1])\n\n    return interfaces\n\n\ndef get_working_if():\n    \"\"\"Returns the first interface than can be used with BPF\"\"\"\n\n    ifaces = get_working_ifaces()\n    if not ifaces:\n        # A better interface will be selected later using the routing table\n        return LOOPBACK_NAME\n    return ifaces[0][0]\n", "path": "scapy/arch/bpf/core.py"}], "after_files": [{"content": "# Guillaume Valadon <guillaume@valadon.net>\n\n\"\"\"\nScapy *BSD native support - core\n\"\"\"\n\nfrom __future__ import absolute_import\n\nfrom ctypes import cdll, cast, pointer\nfrom ctypes import c_int, c_ulong, c_char_p\nfrom ctypes.util import find_library\nimport fcntl\nimport os\nimport re\nimport socket\nimport struct\n\nfrom scapy.arch.bpf.consts import BIOCSETF, SIOCGIFFLAGS, BIOCSETIF\nfrom scapy.arch.common import get_if, compile_filter\nfrom scapy.config import conf\nfrom scapy.consts import LOOPBACK_NAME\nfrom scapy.data import ARPHDR_LOOPBACK, ARPHDR_ETHER\nfrom scapy.error import Scapy_Exception, warning\nfrom scapy.modules.six.moves import range\n\n\n# ctypes definitions\n\nLIBC = cdll.LoadLibrary(find_library(\"libc\"))\nLIBC.ioctl.argtypes = [c_int, c_ulong, c_char_p]\nLIBC.ioctl.restype = c_int\n\n\n# Addresses manipulation functions\n\ndef get_if_raw_addr(ifname):\n    \"\"\"Returns the IPv4 address configured on 'ifname', packed with inet_pton.\"\"\"  # noqa: E501\n\n    # Get ifconfig output\n    try:\n        fd = os.popen(\"%s %s\" % (conf.prog.ifconfig, ifname))\n    except OSError as msg:\n        warning(\"Failed to execute ifconfig: (%s)\", msg)\n        return b\"\\0\\0\\0\\0\"\n\n    # Get IPv4 addresses\n    addresses = [l for l in fd if l.find(\"inet \") >= 0]\n    if not addresses:\n        warning(\"No IPv4 address found on %s !\", ifname)\n        return b\"\\0\\0\\0\\0\"\n\n    # Pack the first address\n    address = addresses[0].split(' ')[1]\n    if '/' in address:  # NetBSD 8.0\n        address = address.split(\"/\")[0]\n    return socket.inet_pton(socket.AF_INET, address)\n\n\ndef get_if_raw_hwaddr(ifname):\n    \"\"\"Returns the packed MAC address configured on 'ifname'.\"\"\"\n\n    NULL_MAC_ADDRESS = b'\\x00' * 6\n\n    # Handle the loopback interface separately\n    if ifname == LOOPBACK_NAME:\n        return (ARPHDR_LOOPBACK, NULL_MAC_ADDRESS)\n\n    # Get ifconfig output\n    try:\n        fd = os.popen(\"%s %s\" % (conf.prog.ifconfig, ifname))\n    except OSError as msg:\n        raise Scapy_Exception(\"Failed to execute ifconfig: (%s)\" % msg)\n\n    # Get MAC addresses\n    addresses = [l for l in fd.readlines() if l.find(\"ether\") >= 0 or\n                 l.find(\"lladdr\") >= 0 or\n                 l.find(\"address\") >= 0]\n    if not addresses:\n        raise Scapy_Exception(\"No MAC address found on %s !\" % ifname)\n\n    # Pack and return the MAC address\n    mac = addresses[0].split(' ')[1]\n    mac = [chr(int(b, 16)) for b in mac.split(':')]\n    return (ARPHDR_ETHER, ''.join(mac))\n\n\n# BPF specific functions\n\ndef get_dev_bpf():\n    \"\"\"Returns an opened BPF file object\"\"\"\n\n    # Get the first available BPF handle\n    for bpf in range(256):\n        try:\n            fd = os.open(\"/dev/bpf%i\" % bpf, os.O_RDWR)\n            return (fd, bpf)\n        except OSError:\n            continue\n\n    raise Scapy_Exception(\"No /dev/bpf handle is available !\")\n\n\ndef attach_filter(fd, bpf_filter, iface):\n    \"\"\"Attach a BPF filter to the BPF file descriptor\"\"\"\n    bp = compile_filter(bpf_filter, iface)\n    # Assign the BPF program to the interface\n    ret = LIBC.ioctl(c_int(fd), BIOCSETF, cast(pointer(bp), c_char_p))\n    if ret < 0:\n        raise Scapy_Exception(\"Can't attach the BPF filter !\")\n\n\n# Interface manipulation functions\n\ndef get_if_list():\n    \"\"\"Returns a list containing all network interfaces.\"\"\"\n\n    # Get ifconfig output\n    try:\n        fd = os.popen(\"%s -a\" % conf.prog.ifconfig)\n    except OSError as msg:\n        raise Scapy_Exception(\"Failed to execute ifconfig: (%s)\" % msg)\n\n    # Get interfaces\n    interfaces = [line[:line.find(':')] for line in fd.readlines()\n                  if \": flags\" in line.lower()]\n    return interfaces\n\n\n_IFNUM = re.compile(\"([0-9]*)([ab]?)$\")\n\n\ndef get_working_ifaces():\n    \"\"\"\n    Returns an ordered list of interfaces that could be used with BPF.\n    Note: the order mimics pcap_findalldevs() behavior\n    \"\"\"\n\n    # Only root is allowed to perform the following ioctl() call\n    if os.getuid() != 0:\n        return []\n\n    # Test all network interfaces\n    interfaces = []\n    for ifname in get_if_list():\n\n        # Unlike pcap_findalldevs(), we do not care of loopback interfaces.\n        if ifname == LOOPBACK_NAME:\n            continue\n\n        # Get interface flags\n        try:\n            result = get_if(ifname, SIOCGIFFLAGS)\n        except IOError:\n            warning(\"ioctl(SIOCGIFFLAGS) failed on %s !\", ifname)\n            continue\n\n        # Convert flags\n        ifflags = struct.unpack(\"16xH14x\", result)[0]\n        if ifflags & 0x1:  # IFF_UP\n\n            # Get a BPF handle\n            fd = get_dev_bpf()[0]\n            if fd is None:\n                raise Scapy_Exception(\"No /dev/bpf are available !\")\n\n            # Check if the interface can be used\n            try:\n                fcntl.ioctl(fd, BIOCSETIF, struct.pack(\"16s16x\",\n                                                       ifname.encode()))\n            except IOError:\n                pass\n            else:\n                ifnum, ifab = _IFNUM.search(ifname).groups()\n                interfaces.append((ifname, int(ifnum) if ifnum else -1, ifab))\n            finally:\n                # Close the file descriptor\n                os.close(fd)\n\n    # Sort to mimic pcap_findalldevs() order\n    interfaces.sort(key=lambda elt: (elt[1], elt[2], elt[0]))\n\n    return [iface[0] for iface in interfaces]\n\n\ndef get_working_if():\n    \"\"\"Returns the first interface than can be used with BPF\"\"\"\n\n    ifaces = get_working_ifaces()\n    if not ifaces:\n        # A better interface will be selected later using the routing table\n        return LOOPBACK_NAME\n    return ifaces[0]\n", "path": "scapy/arch/bpf/core.py"}]}