I've installed pypy and installed scapy for pypy. In pypy website scapy is listed as compatible module. But when I tried this,
>>>> from scapy.all import *
>>>> sendp(Ether()/IP(dst='172.16.0.2'))
It gave an error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/pypy-2.2.1/site-packages/scapy/sendrecv.py", line 255, in sendp
__gen_send(conf.L2socket(iface=iface, *args, **kargs), x, inter=inter, loop=loop, count=count, verbose=verbose, realtime=realtime)
File "/usr/lib64/pypy-2.2.1/site-packages/scapy/arch/linux.py", line 414, in __init__
self.ins.bind((iface, type))
File "<string>", line 1, in bind
error: unknown address family
Then I googled it, and tried to do the same following this link:
>>>> from scapy.layers.inet import IP, Ether
>>>> from scapy.sendrecv import sendp
>>>> sendp(IP(dst='172.16.0.2'))
I still get the exact same error. I thought may be with sendp()
some error might be there. so I tried the exact code mentioned in that link:
>>>> from scapy.layers.inet import IP
>>>> from scapy.sendrecv import send
>>>> send(IP(dst='172.16.0.2'))
No doubt it's not a success, but the error message changes completely saying:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/pypy-2.2.1/site-packages/scapy/sendrecv.py", line 247, in send
__gen_send(conf.L3socket(*args, **kargs), x, inter=inter, loop=loop, count=count,verbose=verbose, realtime=realtime)
File "/usr/lib64/pypy-2.2.1/site-packages/scapy/sendrecv.py", line 230, in __gen_send
s.send(p)
File "/usr/lib64/pypy-2.2.1/site-packages/scapy/arch/linux.py", line 372, in send
iff,a,gw = x.route()
File "/usr/lib64/pypy-2.2.1/site-packages/scapy/layers/inet.py", line 358, in route
return conf.route.route(dst)
AttributeError: 'NoneType' object has no attribute 'route'
Can anybody help me how to work around scapy in pypy? I've my code in python which sniffs a packet from pcap file, modifies few fields in the packet and sends it. Which runs completely fine except the 10ms time it takes which is quite long. I thought of trying to make it less using pypy. But I can't find any solution to the above errors.
Updated: (After testing for address family)
I couldn't find a way to check with pdb
. but I checked by taking other IP addresses:
p=Ether()/IP(src='127.0.0.1', dst='172.16.0.2')
was showing "unkown address family"
error for even p.show()
.
But p=Ether()/IP(src='127.0.0.1', dst='127.0.0.1')
is showing the packet details with p.show()
but showing same error with send()
or sendp()
.
Fixed in PyPy. If this were a bug report I would close it. :-)
The closed bug report is https://bitbucket.org/pypy/pypy/issue/1090/cant-bind-packet-socket.