Skip to content

Commit

Permalink
user: fix the bug where the network card ID cannot be found when writ…
Browse files Browse the repository at this point in the history
…ing to a pcapng file. (#347)

Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
  • Loading branch information
cfc4n committed Apr 28, 2023
1 parent 4ba17fe commit 2f69131
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions user/module/probe_tc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 2f69131

Please sign in to comment.