package util import ( "github.com/google/gopacket" "github.com/google/gopacket/layers" "github.com/google/gopacket/pcapgo" log "github.com/sirupsen/logrus" "io/ioutil" "os" ) func WritePcap(file string, data []byte, ci gopacket.CaptureInfo) { f, err := os.Create(file) if err != nil { log.Errorf("Error writing pcap file %s", file) } defer f.Close() r, err := pcapgo.NewNgWriter(f, layers.LinkTypeEthernet) if err != nil { log.Errorf("Error writing pcap file %s", file) } defer r.Flush() err = r.WritePacket(ci, data) } func WriteBinary(file string, data []byte) { if err := ioutil.WriteFile(file, data, 0644); err != nil { log.Errorf("Error writing binary file %s", file) } }