-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (40 loc) · 823 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"os"
"github.com/bwNetFlow/bpf_flowexport/flowexport"
"github.com/bwNetFlow/bpf_flowexport/packetdump"
)
func usage() {
fmt.Printf("Usage: %v <ifdev>\n", os.Args[0])
fmt.Printf("e.g.: %v eth0\n", os.Args[0])
os.Exit(1)
}
func main() {
if len(os.Args) != 2 {
usage()
}
device := os.Args[1]
// setup bpf dumping
dumper := &packetdump.PacketDumper{}
err := dumper.Setup(device)
if err != nil {
fmt.Println(err)
}
err = dumper.Start()
if err != nil {
fmt.Println(err)
}
defer dumper.Stop()
// setup flow export from the dumped packets
fmap, err := flowexport.NewFlowExporter("30m", "15s")
if err != nil {
fmt.Println(err)
}
fmap.Start()
defer fmap.Stop()
go fmap.ConsumeFrom(dumper.Packets())
for flow := range fmap.Flows {
fmt.Printf("%s\n", flow)
}
}