Process captured packets and generate statistics
(self)
| 648 | |
| 649 | try: |
| 650 | self._stop_sidecars() |
| 651 | except Exception as exc: |
| 652 | logger.debug(f"Sidecar shutdown failed: {exc}") |
| 653 | |
| 654 | if self._capture_process: |
| 655 | try: |
| 656 | self._capture_process.terminate() |
| 657 | self._capture_process.wait(timeout=5) |
| 658 | except Exception as e: |
| 659 | logger.error(f"Error stopping capture: {e}") |
| 660 | try: |
| 661 | self._capture_process.kill() |
| 662 | except Exception: |
| 663 | pass |
| 664 | |
| 665 | logger.info("Traffic analyzer stopped") |
| 666 | |
| 667 | def _capture_loop(self): |
| 668 | """Main capture loop using tcpdump""" |
| 669 | try: |
| 670 | # Build tcpdump command |
| 671 | # -l: line-buffered, -n: no DNS resolution, -q: quiet (brief output) |
| 672 | # -tttt: timestamp format |
| 673 | cmd = [ |
| 674 | 'sudo', 'tcpdump', |
| 675 | '-i', self.interface, |
| 676 | '-l', '-n', '-q', |
| 677 | '-tttt', |
| 678 | 'not port 22 and not port 8000' # Exclude SSH and web UI traffic |
| 679 | ] |
| 680 | |
| 681 | logger.info(f"Starting tcpdump: {' '.join(cmd)}") |
| 682 | |
| 683 | self._capture_process = subprocess.Popen( |
| 684 | cmd, |
| 685 | stdout=subprocess.PIPE, |
| 686 | stderr=subprocess.PIPE, |
| 687 | text=True, |
| 688 | bufsize=1 |
| 689 | ) |
| 690 | |
| 691 | # Start stderr reader thread to capture errors |
nothing calls this directly
no test coverage detected