MCPcopy
hub / github.com/google/gopacket / WriteFileHeader

Method WriteFileHeader

pcapgo/write.go:80–96  ·  view source on GitHub ↗

WriteFileHeader writes a file header out to the writer. This must be called exactly once per output.

(snaplen uint32, linktype layers.LinkType)

Source from the content-addressed store, hash-verified

78// WriteFileHeader writes a file header out to the writer.
79// This must be called exactly once per output.
80func (w *Writer) WriteFileHeader(snaplen uint32, linktype layers.LinkType) error {
81 var buf [24]byte
82 if w.tsScaler == nanosPerMicro {
83 binary.LittleEndian.PutUint32(buf[0:4], magicMicroseconds)
84 } else {
85 binary.LittleEndian.PutUint32(buf[0:4], magicNanoseconds)
86 }
87 binary.LittleEndian.PutUint16(buf[4:6], versionMajor)
88 binary.LittleEndian.PutUint16(buf[6:8], versionMinor)
89 // bytes 8:12 stay 0 (timezone = UTC)
90 // bytes 12:16 stay 0 (sigfigs is always set to zero, according to
91 // http://wiki.wireshark.org/Development/LibpcapFileFormat
92 binary.LittleEndian.PutUint32(buf[16:20], snaplen)
93 binary.LittleEndian.PutUint32(buf[20:24], uint32(linktype))
94 _, err := w.w.Write(buf[:])
95 return err
96}
97
98const nanosPerMicro = 1000
99const nanosPerNano = 1

Callers 4

TestPCAPGoWriteFunction · 0.95
Example_captureEthernetFunction · 0.95
TestWriteHeaderFunction · 0.95
TestWriteHeaderNanosFunction · 0.80

Calls 1

WriteMethod · 0.80

Tested by 4

TestPCAPGoWriteFunction · 0.76
Example_captureEthernetFunction · 0.76
TestWriteHeaderFunction · 0.76
TestWriteHeaderNanosFunction · 0.64