Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3: scapy can't load libpcap #186294

Closed
wilhelmy opened this issue Aug 12, 2022 · 0 comments · Fixed by #186349
Closed

python3: scapy can't load libpcap #186294

wilhelmy opened this issue Aug 12, 2022 · 0 comments · Fixed by #186349

Comments

@wilhelmy
Copy link

Describe the bug

After installing scapy and libpcap via nixpkgs, I tried to use scapy's libpcap support using a filter expression. This fails, claiming nothing provides libpcap.

Steps To Reproduce

Steps to reproduce the behavior:

  1. nix-shell -p python39Packages.scapy -p libpcap --run 'sudo scapy'
  2. AsyncSniffer(iface="wlo1",count=200,filter="icmp6").start()
    ERROR: Cannot set filter: libpcap is not available. Cannot compile filter !

Expected behavior

scapy starts sniffing and filtering packets.

Additional context

I've identified the source of the problem in lib/python3.9/site-packages/scapy/libs/winpcapy.py, which tries to load libpcap via python's ctypes package. I've manually called the corresponding python calls from a REPL and discovered that the call to the CDLL constructor needs the full path to the library on NixOS, presumably because of different library locations in the nix store vs where it's expected on other Linux systems. Related issue: #7307

>>> import ctypes, ctypes.util
>>> ctypes.util.find_library('pcap')
'libpcap.so.1'
>>> ctypes.CDLL('libpcap.so.1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nix/store/xpwwghl72bb7f48m51amvqiv1l25pa01-python3-3.9.13/lib/python3.9/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libpcap.so.1: cannot open shared object file: No such file or directory
>>> ctypes.CDLL('/nix/store/zghjn85hhlkr81n32rqy0r5lvf96nsn8-libpcap-1.10.1/lib/libpcap.so.1')
<CDLL '/nix/store/zghjn85hhlkr81n32rqy0r5lvf96nsn8-libpcap-1.10.1/lib/libpcap.so.1', handle 738b20 at 0x7f2eac85c8b0>

Notify maintainers

@primeos @bjornfor

Metadata

  • system: "x86_64-linux"
  • host os: Linux 5.15.54, NixOS, 22.05 (Quokka), 22.05.1744.07a2e6a4e31
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.8.1
  • channels(mw): "home-manager-22.05.tar.gz"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos
bjornfor added a commit that referenced this issue Oct 30, 2022
This allows doing packet capture directly from scapy.

Fixes #186294.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants