January 2018
Intermediate to advanced
340 pages
8h 6m
English
In some cases, there may be raw bytes that you want to convert into a packet or vice versa. This example creates a simple packet and then obtains the raw bytes that make up the packet. The raw bytes are then taken and converted back into a packet to demonstrate the process.
In this example, we will create and serialize a packet using gopacket.SerializeLayers(). The packet consists of several layers: Ethernet, IP, TCP, and payload. During serialization, if any of the packets come back as nil, this means that it could not decode it into the proper layer (malformed or incorrect packet type). After serializing the packet into a buffer, we will get a copy of the raw bytes that make up the packet with buffer.Bytes() ...
Read now
Unlock full access