[pypy-issue] Issue #3114: SO_ATTACH_FILTER (pypy/pypy)
issues-reply at bitbucket.org
Wed Nov 13 07:26:06 EST 2019
New issue 3114: SO_ATTACH_FILTER
The following call is made on a raw socket:
sock.setsockopt(socket.SOL_SOCKET, SO_ATTACH_FILTER, bp)
Where bp is a `bpf_program` C structure \( generated using libpcap’s `compile_filter`\) that we recreated using
You import ctypes
""""The BPF instruction data structure"""
_fields_ = [("code", ctypes.c_ushort),
""""Structure for BIOCSETF"""
_fields_ = [('bf_len', ctypes.c_int),
This approach \(following Linux' docs for : `SO_ATTACH_FILTER`[http://man7.org/linux/man-pages/man7/socket.7.html](http://man7.org/linux/man-pages/man7/socket.7.html)\) works in both 2.7 and 3 versions of CPython, and fails with
> TypeError: expected bytes, got bpf\_program object
On Pypy3 \(7.1.1 beta0\) \(note actually all pypy versions\).
The full code is actually quite long, as it contains libpcap bindings, socket creation…
To debug the issue, you can get this modified version of Scapy:
Make sure libpcap is installed and run `sudo pypy3 -m scapy` then type `sniff(filter=”tcp”)`.
FTR on master, we have to carry around old compatibility functions to make this work for PyPy using bytes based filters \(`https://github.com/secdev/scapy/blob/43fda76e560e3c94ab64fc23f8ee29c582b459be/scapy/arch/common.py#L111`\) which we would like to be able to drop.
Thanks for the support
More information about the pypy-issue