d1805f60af
Make it easier to re-use the sniffer class in other test support scripts.
26 lines
556 B
Python
26 lines
556 B
Python
# $FreeBSD$
|
|
|
|
import threading
|
|
import scapy.all as sp
|
|
|
|
class Sniffer(threading.Thread):
|
|
def __init__(self, args, check_function):
|
|
threading.Thread.__init__(self)
|
|
|
|
self._args = args
|
|
self._recvif = args.recvif[0]
|
|
self._check_function = check_function
|
|
self.foundCorrectPacket = False
|
|
|
|
self.start()
|
|
|
|
def _checkPacket(self, packet):
|
|
ret = self._check_function(self._args, packet)
|
|
if ret:
|
|
self.foundCorrectPacket = True
|
|
return ret
|
|
|
|
def run(self):
|
|
self.packets = sp.sniff(iface=self._recvif,
|
|
stop_filter=self._checkPacket, timeout=3)
|