From 2f6913122c265ec1781e8a8eba1fb6132f2d341d Mon Sep 17 00:00:00 2001 From: CFC4N Date: Fri, 28 Apr 2023 22:36:22 +0800 Subject: [PATCH] user: fix the bug where the network card ID cannot be found when writing to a pcapng file. (#347) Signed-off-by: CFC4N --- user/module/probe_tc.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/user/module/probe_tc.go b/user/module/probe_tc.go index 02872a46b..ac534020a 100644 --- a/user/module/probe_tc.go +++ b/user/module/probe_tc.go @@ -45,7 +45,7 @@ type MTCProbe struct { func (this *MTCProbe) dumpTcSkb(tcEvent *event.TcSkbEvent) error { var timeStamp = this.bootTime + tcEvent.Ts - return this.writePacket(tcEvent.Len, this.ifIdex, time.Unix(0, int64(timeStamp)), tcEvent.Payload()) + return this.writePacket(tcEvent.Len, time.Unix(0, int64(timeStamp)), tcEvent.Payload()) } // save pcapng file ,merge master key into pcapng file TODO @@ -127,12 +127,16 @@ func (this *MTCProbe) createPcapng(netIfs []net.Interface) error { return nil } -func (this *MTCProbe) writePacket(dataLen uint32, ifaceIdx int, timeStamp time.Time, packetBytes []byte) error { +func (this *MTCProbe) writePacket(dataLen uint32, timeStamp time.Time, packetBytes []byte) error { info := gopacket.CaptureInfo{ - Timestamp: timeStamp, - CaptureLength: int(dataLen), - Length: int(dataLen), - InterfaceIndex: ifaceIdx, + Timestamp: timeStamp, + CaptureLength: int(dataLen), + Length: int(dataLen), + + // set 0 default, Because the monitored network interface is the first one written into the pcapng header. + // 设置为0,因为被监听的网卡是第一个写入pcapng header中的。 + // via : https://github.com/gojue/ecapture/issues/347 + InterfaceIndex: 0, } packet := &TcPacket{info: info, data: packetBytes}