Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

go - gopacket: Use a custom layer 4 protocol

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...