Skip to content

Instantly share code, notes, and snippets.

@jeanqasaur
Last active May 4, 2021 04:42
Show Gist options
  • Save jeanqasaur/dc06126bbfd648d5e3ee7775830056e4 to your computer and use it in GitHub Desktop.
Save jeanqasaur/dc06126bbfd648d5e3ee7775830056e4 to your computer and use it in GitHub Desktop.
Example of using StreamFactory, StreamPool, and Assembler for TCP packet parsing
func (p *NetworkTrafficParser) ParseFromInterface(
interfaceName, bpfFilter string, signalClose <-chan struct{},
fs ...akinet.TCPParserFactory)
(<-chan akinet.ParsedNetworkTraffic, error) {
// Read in packets, pass to assembler
packets, err := p.pcap.capturePackets(signalClose,
interfaceName,
bpfFilter)
if err != nil {
return nil, errors.Wrapf(
err, "failed begin capturing packets from %s",
interfaceName)
}
// Set up assembly
out := make(chan akinet.ParsedNetworkTraffic, 100)
streamFactory := newTCPStreamFactory(
p.clock, out, akinet.TCPParserFactorySelector(fs))
streamPool := reassembly.NewStreamPool(streamFactory)
assembler := reassembly.NewAssembler(streamPool)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment