| 99 | const nanosPerNano = 1 |
| 100 | |
| 101 | func (w *Writer) writePacketHeader(ci gopacket.CaptureInfo) error { |
| 102 | t := ci.Timestamp |
| 103 | if t.IsZero() { |
| 104 | t = time.Now() |
| 105 | } |
| 106 | secs := t.Unix() |
| 107 | usecs := t.Nanosecond() / w.tsScaler |
| 108 | binary.LittleEndian.PutUint32(w.buf[0:4], uint32(secs)) |
| 109 | binary.LittleEndian.PutUint32(w.buf[4:8], uint32(usecs)) |
| 110 | binary.LittleEndian.PutUint32(w.buf[8:12], uint32(ci.CaptureLength)) |
| 111 | binary.LittleEndian.PutUint32(w.buf[12:16], uint32(ci.Length)) |
| 112 | _, err := w.w.Write(w.buf[:]) |
| 113 | return err |
| 114 | } |
| 115 | |
| 116 | // WritePacket writes the given packet data out to the file. |
| 117 | func (w *Writer) WritePacket(ci gopacket.CaptureInfo, data []byte) error { |