Prisacari Dmitrii
Prisacari Dmitrii

Reputation: 2106

Go: How to remove data link layer from a packet?

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?

Upvotes: 2

Views: 417

Answers (1)

Prisacari Dmitrii
Prisacari Dmitrii

Reputation: 2106

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.

Upvotes: 0

Related Questions