Skip to content

Commit

Permalink
Fix ctypes usage with Python 3.9
Browse files Browse the repository at this point in the history
There is a regression in Python 3.9 with the `find_library()`
function:

    >>> import ctypes.util
    >>> ctypes.util.find_library("libc")
     Traceback (most recent call last):
       File "<stdin>", line 1, in <module>
       File "/usr/lib/python3.9/ctypes/util.py", line 341, in find_library
         _get_soname(_findLib_gcc(name)) or _get_soname(_findLib_ld(name))
       File "/usr/lib/python3.9/ctypes/util.py", line 147, in _findLib_gcc
         if not _is_elf(file):
       File "/usr/lib/python3.9/ctypes/util.py", line 99, in _is_elf
         with open(filename, 'br') as thefile:
     FileNotFoundError: [Errno 2] No such file or directory: b'liblibc.a'

A workaround is to use `find_library("c")` instead. It also works in
older versions of Python and that's already what's used in
`contrib/isotp.py`.

Python issue reported here:
 https://bugs.python.org/issue42580

Signed-off-by: Vincent Bernat <vincent@bernat.ch>
  • Loading branch information
vincentbernat authored and gpotter2 committed Dec 11, 2020
1 parent 81603d1 commit 46fa40f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion scapy/arch/bpf/core.py
Expand Up @@ -32,7 +32,7 @@

# ctypes definitions

LIBC = cdll.LoadLibrary(find_library("libc"))
LIBC = cdll.LoadLibrary(find_library("c"))

LIBC.ioctl.argtypes = [c_int, c_ulong, c_char_p]
LIBC.ioctl.restype = c_int
Expand Down

0 comments on commit 46fa40f

Please sign in to comment.