Permalink
Browse files

Convert packet time to time.Time.

  • Loading branch information...
1 parent 2803ae2 commit a8af7f1e179ff95c47265d089b127e53b96e1dee @dustin dustin committed Feb 17, 2012
Showing with 9 additions and 0 deletions.
  1. +9 −0 io.go
View
9 io.go
@@ -3,6 +3,7 @@ package pcap
import (
"fmt"
"io"
+ "time"
)
// FileHeader is the parsed header of a pcap file.
@@ -22,7 +23,15 @@ type PacketTime struct {
Usec int32
}
+// Convert the PacketTime to a go Time struct.
+func (p *PacketTime) Time() time.Time {
+ return time.Unix(int64(p.Sec), int64(p.Usec)*1000)
+}
+
// Packet is a single packet parsed from a pcap file.
+//
+// Convenient access to IP, TCP, and UDP headers is provided after Decode()
+// is called if the packet is of the appropriate type.
type Packet struct {
Time PacketTime // packet send/receive time
Caplen uint32 // bytes stored in the file (caplen <= len)

0 comments on commit a8af7f1

Please sign in to comment.