MCPcopy Index your code
hub / github.com/google/gopacket / writeSectionHeader

Method writeSectionHeader

pcapgo/ngwrite.go:187–234  ·  view source on GitHub ↗

writeSectionHeader writes a section header to the file

()

Source from the content-addressed store, hash-verified

185
186// writeSectionHeader writes a section header to the file
187func (w *NgWriter) writeSectionHeader() error {
188 var scratch [4]ngOption
189 i := 0
190 info := w.options.SectionInfo
191 if info.Application != "" {
192 scratch[i].code = ngOptionCodeUserApplication
193 scratch[i].raw = info.Application
194 i++
195 }
196 if info.Comment != "" {
197 scratch[i].code = ngOptionCodeComment
198 scratch[i].raw = info.Comment
199 i++
200 }
201 if info.Hardware != "" {
202 scratch[i].code = ngOptionCodeHardware
203 scratch[i].raw = info.Hardware
204 i++
205 }
206 if info.OS != "" {
207 scratch[i].code = ngOptionCodeOS
208 scratch[i].raw = info.OS
209 i++
210 }
211 options := scratch[:i]
212
213 length := prepareNgOptions(options) +
214 24 + // header
215 4 // trailer
216
217 binary.LittleEndian.PutUint32(w.buf[:4], uint32(ngBlockTypeSectionHeader))
218 binary.LittleEndian.PutUint32(w.buf[4:8], length)
219 binary.LittleEndian.PutUint32(w.buf[8:12], ngByteOrderMagic)
220 binary.LittleEndian.PutUint16(w.buf[12:14], ngVersionMajor)
221 binary.LittleEndian.PutUint16(w.buf[14:16], ngVersionMinor)
222 binary.LittleEndian.PutUint64(w.buf[16:24], 0xFFFFFFFFFFFFFFFF) // unspecified
223 if _, err := w.w.Write(w.buf[:24]); err != nil {
224 return err
225 }
226
227 if err := w.writeOptions(options); err != nil {
228 return err
229 }
230
231 binary.LittleEndian.PutUint32(w.buf[0:4], length)
232 _, err := w.w.Write(w.buf[:4])
233 return err
234}
235
236// AddInterface adds the specified interface to the file, excluding statistics. Interface timestamp resolution is fixed to 9 (to match time.Time). Empty values are not written.
237func (w *NgWriter) AddInterface(intf NgInterface) (id int, err error) {

Callers 1

NewNgWriterInterfaceFunction · 0.95

Calls 3

writeOptionsMethod · 0.95
prepareNgOptionsFunction · 0.85
WriteMethod · 0.80

Tested by

no test coverage detected