Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions scapy/sendrecv.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,10 @@ def __init__(self, *args, **kwargs):
# type: (*Any, **Any) -> None
# Store keyword arguments
self.args = args
if "timeout" in kwargs:
raise ValueError(
"'timeout' isn't supported with AsyncSniffer. Use join(timeout=1)"
)
self.kwargs = kwargs
self.running = False
self.thread = None # type: Optional[Thread]
Expand Down
6 changes: 3 additions & 3 deletions test/contrib/automotive/ccp.uts
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ def answer(pkt):
assert cro.data == b"\x10\x11\x12\x10\x11\x12"
sock2.send(CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x53\x02\x34\x00\x20\x06'))

sniffer = AsyncSniffer(opened_socket=sock2, count=1, timeout=5, prn=answer)
sniffer = AsyncSniffer(opened_socket=sock2, count=1, prn=answer)
sniffer.start()
dto = sock1.sr1(CCP(identifier=0x700)/CRO(ctr=0x53)/PROGRAM_6(data=b"\x10\x11\x12\x10\x11\x12"), timeout=1, verbose=False)
sniffer.join(timeout=5)
Expand All @@ -915,7 +915,7 @@ def answer(pkt):
assert cro.data == b"\x10\x11\x12\x10\x11\x12"
sock2.send(CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x55\x02\x34\x00\x20\x06'))

sniffer = AsyncSniffer(opened_socket=sock2, count=1, timeout=5, prn=answer)
sniffer = AsyncSniffer(opened_socket=sock2, count=1, prn=answer)
sniffer.start()
dto = sock1.sr1(CCP(identifier=0x700)/CRO(ctr=0x54)/PROGRAM_6(data=b"\x10\x11\x12\x10\x11\x12"), timeout=0.1, verbose=False)
sniffer.join(timeout=5)
Expand All @@ -936,7 +936,7 @@ def answer(pkt):
assert cro.data == b"\x10\x11\x12\x10\x11\x12"
sock2.send(CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x01\x55\xff\xff\xff\xff\xff'))

sniffer = AsyncSniffer(opened_socket=sock2, count=1, timeout=5, prn=answer)
sniffer = AsyncSniffer(opened_socket=sock2, count=1, prn=answer)
sniffer.start()
dto = sock1.sr1(CCP(identifier=0x700)/CRO(ctr=0x55)/PROGRAM_6(data=b"\x10\x11\x12\x10\x11\x12"), timeout=1, verbose=False)
sniffer.join(timeout=5)
Expand Down
13 changes: 8 additions & 5 deletions test/contrib/automotive/testsocket.uts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def create_answer(p):
ans = TestPacket(identifier=p.identifier + 1, data=p.data + b"_answer")
receiver.send(ans)

t = AsyncSniffer(timeout=50, prn=create_answer, opened_socket=receiver)
t = AsyncSniffer(prn=create_answer, opened_socket=receiver)
t.start()

pks = PacketList()
Expand All @@ -51,7 +51,8 @@ for i in range(1, 2000, 2):
pks.append(txp)
pks.append(rxp)

t.stop(join=True)
t.join(timeout=10)
t.stop()
convs = pks.sr()

sender.close()
Expand All @@ -69,12 +70,13 @@ sender = TestSocket(TestPacket)
receiver = TestSocket(TestPacket)
sender.pair(receiver)

t = AsyncSniffer(timeout=10, prn=create_answer, opened_socket=receiver)
t = AsyncSniffer(prn=create_answer, opened_socket=receiver)
t.start()

txp = TestPacket(identifier=range(1, testlen * 2, 2), data=b"test1")
rxp = sender.sr(txp, timeout=10, verbose=False, prebuild=True)
t.stop(join=True)
t.join(timeout=10)
t.stop()

print(rxp)
print(rxp[0].summary())
Expand All @@ -91,11 +93,12 @@ sender = TestSocket(TestPacket)
receiver = TestSocket(TestPacket)
sender.pair(receiver)

t = AsyncSniffer(timeout=10, prn=create_answer, opened_socket=receiver)
t = AsyncSniffer(prn=create_answer, opened_socket=receiver)
t.start()

txp = [TestPacket(identifier=i, data=b"hello") for i in range(1, 2000, 2)]
rxp = sender.sr(txp, timeout=10, verbose=False)
t.join(timeout=10)
t.stop(join=True)

print(rxp)
Expand Down
2 changes: 1 addition & 1 deletion test/contrib/automotive/xcp/xcp_comm.uts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sock2 = TestSocket(XCPOnCAN)
sock1.pair(sock2)

response = XCPOnCAN(identifier=0x700) / CTOResponse() / ConnectPositiveResponse(b'\x15\xC0\x08\x08\x00\x10\x10')
sniffer = AsyncSniffer(opened_socket=sock2, count=1, timeout=5, prn=lambda x: sock2.send(response))
sniffer = AsyncSniffer(opened_socket=sock2, count=1, prn=lambda x: sock2.send(response))
sniffer.start()
pkt = XCPOnCAN(identifier=0x700) / CTORequest() / Connect()
ans = sock1.sr1(pkt, timeout=0.5, verbose=False)
Expand Down
8 changes: 4 additions & 4 deletions test/contrib/isotp_soft_socket.uts
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ cans.pair(isocan)

acker = AsyncSniffer(store=False, opened_socket=cans,
prn=lambda x: cans.send(CAN(identifier = 0x241, data=dhex("30 04 00"))),
count=1, timeout=1)
count=1)
acker.start()
with ISOTPSoftSocket(isocan, tx_id=0x641, rx_id=0x241) as s:
s.send(isotp)
Expand All @@ -913,7 +913,7 @@ cans.pair(isocan)
acker = AsyncSniffer(store=False, opened_socket=cans,
prn=lambda x: cans.send(
CAN(identifier = 0x241, data=dhex("32 00 00"))),
count=1, timeout=1)
count=1)
acker.start()

with ISOTPSoftSocket(isocan, tx_id=0x641, rx_id=0x241) as s:
Expand All @@ -934,7 +934,7 @@ msg = ISOTP(b'\x11\x22\x33\x11\x22\x33\x11\x22\x33\x11\x22\x33')
with TestSocket(CAN) as isocan_tx, ISOTPSoftSocket(isocan_tx, 0x123, 0x321) as sock_tx, \
TestSocket(CAN) as isocan_rx, ISOTPSoftSocket(isocan_rx, 0x321, 0x123) as sock_rx:
isocan_rx.pair(isocan_tx)
sniffer = AsyncSniffer(opened_socket=sock_rx, timeout=1, count=1, prn=lambda x: sock_rx.send(msg))
sniffer = AsyncSniffer(opened_socket=sock_rx, count=1, prn=lambda x: sock_rx.send(msg))
sniffer.start()
rx2 = sock_tx.sr1(msg, timeout=3, verbose=True)
sniffer.join(timeout=1)
Expand Down Expand Up @@ -1374,7 +1374,7 @@ acks.pair(cans)
def send_ack(x):
acks.send(CAN(identifier = 0x241, data=dhex("30 00 00")))

acker = AsyncSniffer(opened_socket=acks, store=False, prn=send_ack, timeout=1, count=1)
acker = AsyncSniffer(opened_socket=acks, store=False, prn=send_ack, count=1)
acker.start()

with TestSocket(CAN) as isocan, ISOTPSoftSocket(isocan, tx_id=0x641, rx_id=0x241, padding=True) as s:
Expand Down
1 change: 0 additions & 1 deletion test/linux.uts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ with VEthPair("left0", "right0") as veth:
iface="right0",
lfilter=lambda p: Dot1Q in p,
count=2,
timeout=5,
started_callback=_send,
)
sniffer.start()
Expand Down
Loading