when analyzing pcap files, I always find outputs as follow:
➜ packetbeat git:(master) ✗ ./packetbeat -c ./packetbeat.yml -e -I redis_xxxx.pcap 2>&1 |grep "pcap went backwards"
...
2017/01/11 06:57:47.091832 sniffer.go:365: WARN Time in pcap went backwards: -2000
...
2017/01/11 06:57:47.189023 sniffer.go:365: WARN Time in pcap went backwards: -1000
...
2017/01/11 06:57:47.189238 sniffer.go:365: WARN Time in pcap went backwards: 0
after some source codes digging, I find something I can not understand.
func (sniffer *SnifferSetup) Run() error {
...
if sniffer.config.File != "" {
if lastPktTime != nil && !sniffer.config.TopSpeed {
sleep := ci.Timestamp.Sub(*lastPktTime)
if sleep > 0 {
time.Sleep(sleep)
} else {
logp.Warn("Time in pcap went backwards: %d", sleep)
}
}
_lastPktTime := ci.Timestamp
lastPktTime = &_lastPktTime
if !sniffer.config.TopSpeed {
ci.Timestamp = time.Now() // overwrite what we get from the pcap
}
}
According to the code, if -t option not set, every packet in the pcap file will use current system time as timestamp. However, when computing time difference between two successive packets, the latter one use its real timestamp which is set on capturing. I think it is the root case why "backwards" happends, and I think it is a bug.
right now, when reading packets from pcap files, I always use -t option to avoid annoying "backwards" output.
Can someone tell me if I misunderstanding anything? Tks in advance.

