2

I am using the gopacket library, and I read packets from the wire. Right now, all packets I read contain four layers: Link, Network, Transport, and Application Data.

I need to remove the Link layer from all packets and save the rest to a file. Haven't found any information or docs about making the packet stripping part right.

Does anyone know how to do it?

user207421
  • 305,947
  • 44
  • 307
  • 483
Prisacari Dmitrii
  • 1,985
  • 1
  • 23
  • 33

1 Answers1

0

I found one possible way - to concatenate bytes from necessary packet layers:

// `packet` variable contains four layers including the Link layer 
packet := <-packetSource.Packets()

var packetData []byte
packetData = append(packetData, packet.NetworkLayer().LayerContents()...)
packetData = append(packetData, packet.TransportLayer().LayerContents()...)
packetData = append(packetData, packet.ApplicationLayer().LayerContents()...)

// The `packetData` variable is a []bytes representation of all layers 
// except the Link layer, and it might be written to a *.pcap file.

Prisacari Dmitrii
  • 1,985
  • 1
  • 23
  • 33