Skip to content

Commit

Permalink
Convert PCap/PFRing timestamps correctly.
Browse files Browse the repository at this point in the history
We were incorrectly converting pcap and pfring timestamps into Go time.Time
objects... they returned micros, but we treated them as nanos.

Thanks to Peter Membrey for pointing this out.
  • Loading branch information
gconnell committed Jan 21, 2014
1 parent 2633065 commit ee6c29c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pcap/pcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ func (p *Handle) getNextBufPtrLocked(ci *gopacket.CaptureInfo) error {
return result
}
}
ci.Timestamp = time.Unix(int64(p.pkthdr.ts.tv_sec), int64(p.pkthdr.ts.tv_usec))
ci.Timestamp = time.Unix(int64(p.pkthdr.ts.tv_sec),
int64(p.pkthdr.ts.tv_usec)*1000) // convert micros to nanos
ci.CaptureLength = int(p.pkthdr.caplen)
ci.Length = int(p.pkthdr.len)
return nil
Expand Down
3 changes: 2 additions & 1 deletion pfring/pfring.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ func (r *Ring) ReadPacketDataTo(data []byte) (ci gopacket.CaptureInfo, err error
r.mu.Unlock()
return
}
ci.Timestamp = time.Unix(int64(r.pkthdr.ts.tv_sec), int64(r.pkthdr.ts.tv_usec))
ci.Timestamp = time.Unix(int64(r.pkthdr.ts.tv_sec),
int64(r.pkthdr.ts.tv_usec)*1000) // convert micros to nanos
ci.CaptureLength = int(r.pkthdr.caplen)
ci.Length = int(r.pkthdr.len)
r.mu.Unlock()
Expand Down

0 comments on commit ee6c29c

Please sign in to comment.