Fix async subprocess communication and remove unsupported snaplen parameter
- Fix async subprocess.communicate() usage: await before unpacking tuple Changed from: stderr = await proc.communicate()[1] To: _, stderr = await proc.communicate() - Remove snaplen parameter from sniff() calls (not supported for live interface capture) - Update messages to reflect that full packets are captured for live capture - Remove redundant proc.wait() calls after communicate() Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
96aab517af
commit
9ff3cb9793
|
|
@ -665,10 +665,17 @@ class PacketCapture:
|
|||
test_packets = []
|
||||
try:
|
||||
# Run blocking sniff in executor
|
||||
# Note: snaplen is not supported for live interface capture in scapy
|
||||
loop = asyncio.get_event_loop()
|
||||
sniff_kwargs = {
|
||||
"iface": interface,
|
||||
"prn": lambda pkt: test_packets.append(pkt),
|
||||
"timeout": 1,
|
||||
"store": False
|
||||
}
|
||||
await loop.run_in_executor(
|
||||
None,
|
||||
lambda: sniff(iface=interface, prn=lambda pkt: test_packets.append(pkt), timeout=1, store=False, snaplen=self.config.snaplen)
|
||||
lambda: sniff(**sniff_kwargs)
|
||||
)
|
||||
except OSError as e:
|
||||
print(f"Error during test capture (system error): {e}")
|
||||
|
|
@ -705,7 +712,7 @@ class PacketCapture:
|
|||
if self.config.full_packet:
|
||||
print("Capturing full packets...")
|
||||
else:
|
||||
print(f"Capturing packets (snaplen={self.config.snaplen} bytes, header + some payload)...")
|
||||
print(f"Capturing packets (full packets - snaplen not supported for live capture)...")
|
||||
|
||||
packets = []
|
||||
pcap_path = None
|
||||
|
|
@ -719,11 +726,19 @@ class PacketCapture:
|
|||
capture_error = None
|
||||
try:
|
||||
# Run blocking sniff in executor
|
||||
# Note: snaplen is not supported for live interface capture in scapy
|
||||
# We capture full packets and can truncate in post-processing if needed
|
||||
loop = asyncio.get_event_loop()
|
||||
sniff_kwargs = {
|
||||
"iface": interface,
|
||||
"prn": lambda pkt: packets.append(pkt),
|
||||
"timeout": duration,
|
||||
"store": True
|
||||
}
|
||||
if self.config.keep_pcap:
|
||||
await loop.run_in_executor(
|
||||
None,
|
||||
lambda: sniff(iface=interface, prn=lambda pkt: packets.append(pkt), timeout=duration, store=True, snaplen=self.config.snaplen)
|
||||
lambda: sniff(**sniff_kwargs)
|
||||
)
|
||||
await loop.run_in_executor(None, lambda: wrpcap(pcap_path, packets))
|
||||
print(f"Pcap file size: {os.path.getsize(pcap_path)} bytes")
|
||||
|
|
@ -732,7 +747,7 @@ class PacketCapture:
|
|||
else:
|
||||
await loop.run_in_executor(
|
||||
None,
|
||||
lambda: sniff(iface=interface, prn=lambda pkt: packets.append(pkt), timeout=duration, store=True, snaplen=self.config.snaplen)
|
||||
lambda: sniff(**sniff_kwargs)
|
||||
)
|
||||
except KeyboardInterrupt:
|
||||
print("\nCapture interrupted by user")
|
||||
|
|
|
|||
Loading…
Reference in New Issue