forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpfring.go
50 lines (35 loc) · 916 Bytes
/
pfring.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
49
50
// +build linux,havepfring
package main
import (
"fmt"
"github.com/packetbeat/gopacket"
"github.com/packetbeat/gopacket/pfring"
)
type PfringHandle struct {
Ring *pfring.Ring
}
func NewPfringHandle(device string, snaplen int, promisc bool) (*PfringHandle, error) {
var h PfringHandle
var err error
if device == "any" {
return nil, fmt.Errorf("Pfring sniffing doesn't support 'any' as interface")
}
var flags pfring.Flag
if promisc {
flags = pfring.FlagPromisc
}
h.Ring, err = pfring.NewRing(device, uint32(snaplen), flags)
return &h, err
}
func (h *PfringHandle) ReadPacketData() (data []byte, ci gopacket.CaptureInfo, err error) {
return h.Ring.ReadPacketData()
}
func (h *PfringHandle) SetBPFFilter(expr string) (_ error) {
return h.Ring.SetBPFFilter(expr)
}
func (h *PfringHandle) Enable() (_ error) {
return h.Ring.Enable()
}
func (h *PfringHandle) Close() {
h.Ring.Close()
}