'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?
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Prisacari Dmitrii |