Skip to content

Commit

Permalink
Bugfix: make sure pcapng header is always written
Browse files Browse the repository at this point in the history
If a capture is stopped before the pcapng header is written, when starting a new capture
Wireshark does not open the control input pipe for writing
which causes our extcap to hang when trying to open it.
  • Loading branch information
oshaked1 committed May 28, 2024
1 parent 520976d commit 4ebbfd5
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions extcap/tracee-capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import argparse
from ctypes import cdll, byref, create_string_buffer
import os
import select
from select import select
import shutil
import signal
import socket
Expand Down Expand Up @@ -492,7 +492,9 @@ def _init_pcapng(self) -> pcapng.FileWriter:
)

with self._lock:
return pcapng.FileWriter(self._extcap_pipe_f, shb)
writer = pcapng.FileWriter(self._extcap_pipe_f, shb)
self._extcap_pipe_f.flush()
return writer

def _parse_ts(self, event: bytes) -> int:
if not event.startswith(b'{"timestamp":'):
Expand Down Expand Up @@ -877,8 +879,6 @@ def toolbar_control(control_inf: BinaryIO, control_output_manager: ControlOutput
arg, _, payload = control_read(control_inf)
except OSError:
break
if arg is None:
break
if not running:
break

Expand Down Expand Up @@ -1044,7 +1044,7 @@ def handle_connection(transport: paramiko.Transport, dst_addr: str, dst_port: in
return

while True:
r, _, _ = select.select([sock, channel], [], [])
r, _, _ = select([sock, channel], [], [])
if sock in r:
try:
data = sock.recv(1024)
Expand Down Expand Up @@ -1279,8 +1279,6 @@ def tracee_capture(args: argparse.Namespace):

if len(logs_err) > 0:
error(f'Tracee exited with error message:\n{logs_err}')

control_outf.close()


def handle_reload(option: str, args: argparse.Namespace):
Expand Down

0 comments on commit 4ebbfd5

Please sign in to comment.