diff --git a/inspector.exe b/inspector.exe index 832b21f..5d75e34 100644 Binary files a/inspector.exe and b/inspector.exe differ diff --git a/internal/capture/local.go b/internal/capture/local.go index da8a56c..a4791ab 100644 --- a/internal/capture/local.go +++ b/internal/capture/local.go @@ -9,6 +9,7 @@ import ( "strings" "sync" + "telephony-inspector/internal/logger" "telephony-inspector/internal/sip" ) @@ -50,6 +51,8 @@ func (c *LocalCapturer) Start(iface string, port int) error { args := []string{"-l", "-nn", "-A", "-s", "0", "-i", iface, "port", fmt.Sprintf("%d", port)} c.cmd = exec.CommandContext(ctx, "tcpdump", args...) + logger.Info("Starting local capture: tcpdump %v", args) + stdout, err := c.cmd.StdoutPipe() if err != nil { c.mu.Lock() @@ -73,6 +76,8 @@ func (c *LocalCapturer) Start(iface string, port int) error { return fmt.Errorf("failed to start tcpdump: %w", err) } + logger.Info("Local capture started successfully") + // Process stdout in goroutine go c.processStream(stdout) @@ -90,6 +95,7 @@ func (c *LocalCapturer) Stop() { if !c.running { return } + logger.Info("Stopping local capture") c.running = false if c.cancel != nil { @@ -130,9 +136,11 @@ func (c *LocalCapturer) processStream(r io.Reader) { } line := scanner.Text() + // logger.Debug("Stdout: %s", line) // Commented out to reduce noise, enable if needed // Detect start of SIP message if isSIPStart(line) { + logger.Debug("SIP Start detected: %s", line) // If we were building a message, parse it if buffer.Len() > 0 { c.parseAndEmit(buffer.String()) @@ -159,8 +167,10 @@ func (c *LocalCapturer) processErrors(r io.Reader) { text := scanner.Text() // tcpdump prints "listening on..." to stderr, ignore it if strings.Contains(text, "listening on") { + logger.Info("tcpdump: %s", text) continue } + logger.Error("tcpdump stderr: %s", text) if c.OnError != nil { c.OnError(fmt.Errorf("tcpdump: %s", text)) } @@ -170,12 +180,16 @@ func (c *LocalCapturer) processErrors(r io.Reader) { func (c *LocalCapturer) parseAndEmit(raw string) { packet, err := sip.Parse(raw) if err != nil { + logger.Error("Error parsing SIP packet: %v", err) if c.OnError != nil { c.OnError(err) } return } - if packet != nil && c.OnPacket != nil { - c.OnPacket(packet) + if packet != nil { + logger.Debug("Packet parsed: %s %s -> %s", packet.Method, packet.SourceIP, packet.DestIP) + if c.OnPacket != nil { + c.OnPacket(packet) + } } }