I'd like to use gopacket to decode IP packets with a custom layer 4 protocol inside. I wrote a new layer definition for my custom protocol. Further, I can correctly serialize the layers such that I have a packet with IPv4 Header | Custom Header | Payload
. However, I don't see a nice way to decode the resulting packet into the individual layers again. The problem is that packets are decoded layer by layer, where each layer specifies the decoder to be used for the next layer. Of course, the gopacket
IP decoder doesn't know about my custom protocol and therefore does not use the correct decoder.
One option I see is to wrap the IPv4 layer type and re-implement the NextLayerType function to return the type of my custom header.
The library is quite big and I think I'm missing something.
All the examples I've found so far only show how an outer custom layer can be used. There of course, the problem doesn't arise.
question from:
https://stackoverflow.com/questions/65830822/gopacket-use-a-custom-layer-4-protocol 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…