fix: Extract network metadata from tcpdump headers to populate SIP packet IPs

This commit is contained in:
Jose Luis Montañes Ojados
2026-01-19 15:40:11 +01:00
parent 2d99d8ddc4
commit f0911737f4
3 changed files with 104 additions and 10 deletions

View File

@@ -15,10 +15,11 @@ import (
// LocalCapturer handles SIP packet capture locally via tcpdump
type LocalCapturer struct {
cmd *exec.Cmd
cancel context.CancelFunc
running bool
mu sync.Mutex
cmd *exec.Cmd
cancel context.CancelFunc
running bool
mu sync.Mutex
currentNetInfo *NetInfo
// Callbacks
OnPacket func(*sip.Packet)
@@ -138,6 +139,13 @@ func (c *LocalCapturer) processStream(r io.Reader) {
line := scanner.Text()
// logger.Debug("Stdout: %s", line) // Commented out to reduce noise, enable if needed
// Check for tcpdump header
if netInfo := parseTcpdumpHeader(line); netInfo != nil {
c.currentNetInfo = netInfo
// Proceed to next line
continue
}
// Detect start of SIP message
if idx := findSIPStart(line); idx != -1 {
logger.Debug("SIP Start detected: %s", line)
@@ -190,6 +198,14 @@ func (c *LocalCapturer) parseAndEmit(raw string) {
return
}
if packet != nil {
// Attach network info if available
if c.currentNetInfo != nil {
packet.Timestamp = c.currentNetInfo.Timestamp
packet.SourceIP = c.currentNetInfo.SourceIP
packet.SourcePort = c.currentNetInfo.SourcePort
packet.DestIP = c.currentNetInfo.DestIP
packet.DestPort = c.currentNetInfo.DestPort
}
logger.Debug("Packet parsed: %s %s -> %s", packet.Method, packet.SourceIP, packet.DestIP)
if c.OnPacket != nil {
c.OnPacket(packet)