Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use the tcp assembly package in gopacket?

Tags:

tcp

go

gopacket

I've been using the pcap package along with gopacket to parse network traffic with pretty good success. These libraries have made it much easier to work with network captures and they've definitely saved me a ton of time.

I'd like to take it a step further and use the tcp assembly package to start reassembling TCP streams, but I'm not really sure from the examples provided in the docs how to go about it.

The link is here:

http://godoc.org/code.google.com/p/gopacket/tcpassembly/tcpreader

What I'm looking for is a simple example that demonstrates how to set this up so that you have packets going in one end and a nice byte ordered data stream coming out the other end.

Thanks in advance!

like image 608
PeterM Avatar asked Mar 20 '23 23:03

PeterM


2 Answers

Turns out there is already a full example provided in the main repo:

https://github.com/google/gopacket/blob/master/examples/httpassembly/main.go

Worked great :)

like image 95
PeterM Avatar answered Apr 01 '23 23:04

PeterM


I've added a second example at https://code.google.com/p/gopacket/source/browse/examples/statsassembly/main.go as well, which uses some slightly different patterns, resulting in a binary that can handle higher-throughput sniffing a little easier.

like image 44
user524177 Avatar answered Apr 02 '23 00:04

user524177