scapy
scapy copied to clipboard
Fix sniff timeout when libpcap select returns readable with no packets
Summary
- When
sniff(..., timeout=N)uses a libpcap socket,selectmay report the capture fd as readable even when no BPF-matched packets are available; a blockingpcap_next_exinrecv()could then stall past the sniff timeout (same class as #74). - Timed sniff loops now call
nonblock_recv()when the socket supports it, via anonblockflag on sessionrecv(). - Adds a mock regression test that simulates libpcap always returning the socket from
selectwhilenonblock_recv()yields no packet.
Fixes #4590
Test plan
- [x] New regression test:
sniff timeout with select-ready but empty pcap socket (#4590)intest/regression.uts - [x] Manual verification: mock socket completes within ~1s with
timeout=1, blockingrecv()never called - [ ] CI (UTscapy on Linux with libpcap)
Made with Cursor
Hi & thanks for the PR !
It has great performance implications to use a non blocking read instead of a blocking one. I am therefore not sure that this is the proper way of tackling the issue.