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

Method WritePacket

pcapgo/write.go:117–129  ·  view source on GitHub ↗

WritePacket writes the given packet data out to the file.

(ci gopacket.CaptureInfo, data []byte)

Source from the content-addressed store, hash-verified

115
116// WritePacket writes the given packet data out to the file.
117func (w *Writer) WritePacket(ci gopacket.CaptureInfo, data []byte) error {
118 if ci.CaptureLength != len(data) {
119 return fmt.Errorf("capture length %d does not match data length %d", ci.CaptureLength, len(data))
120 }
121 if ci.CaptureLength > ci.Length {
122 return fmt.Errorf("invalid capture info %+v: capture length > length", ci)
123 }
124 if err := w.writePacketHeader(ci); err != nil {
125 return fmt.Errorf("error writing packet header: %v", err)
126 }
127 _, err := w.w.Write(data)
128 return err
129}

Callers 6

TestPCAPGoWriteFunction · 0.95
Example_captureEthernetFunction · 0.95
TestWritePacketFunction · 0.95
BenchmarkWritePacketFunction · 0.95
TestCaptureInfoErrorsFunction · 0.95
TestNgWriteComplexFunction · 0.45

Calls 2

writePacketHeaderMethod · 0.95
WriteMethod · 0.80

Tested by 6

TestPCAPGoWriteFunction · 0.76
Example_captureEthernetFunction · 0.76
TestWritePacketFunction · 0.76
BenchmarkWritePacketFunction · 0.76
TestCaptureInfoErrorsFunction · 0.76
TestNgWriteComplexFunction · 0.36