Call the sr...() functions with parameter promisc=1 for that. This is needed for the src/sys/netinet/arp regress test and was backported from secdev/scapy master at github. OK danj@ (maintainer)
112 lines
5.3 KiB
Plaintext
112 lines
5.3 KiB
Plaintext
$OpenBSD: patch-scapy_sendrecv_py,v 1.5 2016/12/09 16:40:11 bluhm Exp $
|
|
|
|
https://github.com/secdev/scapy/commit/3983433a3b93d2662e0baf9875a4d33dec743cbe
|
|
https://github.com/secdev/scapy/commit/e41627769f6eba2dc54f102e8e7c0bc246090eec
|
|
|
|
--- scapy/sendrecv.py.orig Tue Oct 18 14:56:50 2016
|
|
+++ scapy/sendrecv.py Fri Dec 9 14:51:03 2016
|
|
@@ -11,7 +11,7 @@ import errno
|
|
import cPickle,os,sys,time,subprocess
|
|
import itertools
|
|
from select import select
|
|
-from scapy.arch.consts import DARWIN, FREEBSD
|
|
+from scapy.arch.consts import DARWIN, FREEBSD, OPENBSD
|
|
from scapy.data import *
|
|
from scapy.config import conf
|
|
from scapy.packet import Gen
|
|
@@ -127,7 +127,7 @@ def sndrcv(pks, pkt, timeout = None, inter = 0, verbos
|
|
if remaintime <= 0:
|
|
break
|
|
r = None
|
|
- if not isinstance(pks, StreamSocket) and (FREEBSD or DARWIN):
|
|
+ if not isinstance(pks, StreamSocket) and (FREEBSD or DARWIN or OPENBSD):
|
|
inp, out, err = select(inmask,[],[], 0.05)
|
|
if len(inp) == 0 or pks in inp:
|
|
r = pks.nonblock_recv()
|
|
@@ -321,7 +321,7 @@ def sendpfast(x, pps=None, mbps=None, realtime=None, l
|
|
|
|
|
|
@conf.commands.register
|
|
-def sr(x,filter=None, iface=None, nofilter=0, *args,**kargs):
|
|
+def sr(x, promisc=None, filter=None, iface=None, nofilter=0, *args,**kargs):
|
|
"""Send and receive packets at layer 3
|
|
nofilter: put 1 to avoid use of bpf filters
|
|
retry: if positive, how many times to resend unanswered packets
|
|
@@ -333,13 +333,13 @@ filter: provide a BPF filter
|
|
iface: listen answers only on the given interface"""
|
|
if not kargs.has_key("timeout"):
|
|
kargs["timeout"] = -1
|
|
- s = conf.L3socket(filter=filter, iface=iface, nofilter=nofilter)
|
|
+ s = conf.L3socket(promisc=promisc, filter=filter, iface=iface, nofilter=nofilter)
|
|
a,b=sndrcv(s,x,*args,**kargs)
|
|
s.close()
|
|
return a,b
|
|
|
|
@conf.commands.register
|
|
-def sr1(x,filter=None,iface=None, nofilter=0, *args,**kargs):
|
|
+def sr1(x, promisc=None, filter=None, iface=None, nofilter=0, *args,**kargs):
|
|
"""Send packets at layer 3 and return only the first answer
|
|
nofilter: put 1 to avoid use of bpf filters
|
|
retry: if positive, how many times to resend unanswered packets
|
|
@@ -351,7 +351,7 @@ filter: provide a BPF filter
|
|
iface: listen answers only on the given interface"""
|
|
if not kargs.has_key("timeout"):
|
|
kargs["timeout"] = -1
|
|
- s=conf.L3socket(filter=filter, nofilter=nofilter, iface=iface)
|
|
+ s=conf.L3socket(promisc=promisc, filter=filter, nofilter=nofilter, iface=iface)
|
|
a,b=sndrcv(s,x,*args,**kargs)
|
|
s.close()
|
|
if len(a) > 0:
|
|
@@ -360,7 +360,7 @@ iface: listen answers only on the given interface""
|
|
return None
|
|
|
|
@conf.commands.register
|
|
-def srp(x,iface=None, iface_hint=None, filter=None, nofilter=0, type=ETH_P_ALL, *args,**kargs):
|
|
+def srp(x, promisc=None, iface=None, iface_hint=None, filter=None, nofilter=0, type=ETH_P_ALL, *args,**kargs):
|
|
"""Send and receive packets at layer 2
|
|
nofilter: put 1 to avoid use of bpf filters
|
|
retry: if positive, how many times to resend unanswered packets
|
|
@@ -374,7 +374,7 @@ iface: work only on the given interface"""
|
|
kargs["timeout"] = -1
|
|
if iface is None and iface_hint is not None:
|
|
iface = conf.route.route(iface_hint)[0]
|
|
- s = conf.L2socket(iface=iface, filter=filter, nofilter=nofilter, type=type)
|
|
+ s = conf.L2socket(promisc=promisc, iface=iface, filter=filter, nofilter=nofilter, type=type)
|
|
a,b=sndrcv(s ,x,*args,**kargs)
|
|
s.close()
|
|
return a,b
|
|
@@ -516,7 +516,7 @@ def sndrcvflood(pks, pkt, prn=lambda (s,r):r.summary()
|
|
return received
|
|
|
|
@conf.commands.register
|
|
-def srflood(x,filter=None, iface=None, nofilter=None, *args,**kargs):
|
|
+def srflood(x, promisc=None, filter=None, iface=None, nofilter=None, *args,**kargs):
|
|
"""Flood and receive packets at layer 3
|
|
prn: function applied to packets received. Ret val is printed if not None
|
|
store: if 1 (default), store answers and return them
|
|
@@ -524,13 +524,13 @@ unique: only consider packets whose print
|
|
nofilter: put 1 to avoid use of bpf filters
|
|
filter: provide a BPF filter
|
|
iface: listen answers only on the given interface"""
|
|
- s = conf.L3socket(filter=filter, iface=iface, nofilter=nofilter)
|
|
+ s = conf.L3socket(promisc=promisc, filter=filter, iface=iface, nofilter=nofilter)
|
|
r=sndrcvflood(s,x,*args,**kargs)
|
|
s.close()
|
|
return r
|
|
|
|
@conf.commands.register
|
|
-def srpflood(x,filter=None, iface=None, iface_hint=None, nofilter=None, *args,**kargs):
|
|
+def srpflood(x, promisc=None, filter=None, iface=None, iface_hint=None, nofilter=None, *args,**kargs):
|
|
"""Flood and receive packets at layer 2
|
|
prn: function applied to packets received. Ret val is printed if not None
|
|
store: if 1 (default), store answers and return them
|
|
@@ -540,7 +540,7 @@ filter: provide a BPF filter
|
|
iface: listen answers only on the given interface"""
|
|
if iface is None and iface_hint is not None:
|
|
iface = conf.route.route(iface_hint)[0]
|
|
- s = conf.L2socket(filter=filter, iface=iface, nofilter=nofilter)
|
|
+ s = conf.L2socket(promisc=promisc, filter=filter, iface=iface, nofilter=nofilter)
|
|
r=sndrcvflood(s,x,*args,**kargs)
|
|
s.close()
|
|
return r
|