forked from david415/HoneyBadger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
36 lines (32 loc) · 978 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
package main
import (
"fmt"
"github.com/david415/HoneyBadger/bpf_sniffer"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
)
func main() {
var err error
sniffer := bpf_sniffer.NewBpfSniffer()
err = sniffer.Init("vio0")
if err != nil {
panic(err)
}
for {
timedFrame := sniffer.ReadTimedFrame()
// Decode a packet
fmt.Printf("timedFrame timestamp %s\n", timedFrame.Timestamp)
packet := gopacket.NewPacket(timedFrame.RawFrame, layers.LayerTypeEthernet, gopacket.Default)
// Get the TCP layer from this packet
if tcpLayer := packet.Layer(layers.LayerTypeTCP); tcpLayer != nil {
fmt.Println("This is a TCP packet!")
// Get actual TCP data from this layer
tcp, _ := tcpLayer.(*layers.TCP)
fmt.Printf("From src port %d to dst port %d\n", tcp.SrcPort, tcp.DstPort)
}
// Iterate over all layers, printing out each layer type
for _, layer := range packet.Layers() {
fmt.Println("PACKET LAYER:", layer.LayerType())
}
}
}