icingabeat/vendor/github.com/elastic/beats/packetbeat/sniffer/afpacket_linux.go

51 lines
1.1 KiB
Go

// +build linux
package sniffer
import (
"time"
"github.com/tsg/gopacket"
"github.com/tsg/gopacket/afpacket"
)
type afpacketHandle struct {
TPacket *afpacket.TPacket
}
func newAfpacketHandle(device string, snaplen int, block_size int, num_blocks int,
timeout time.Duration) (*afpacketHandle, error) {
h := &afpacketHandle{}
var err error
if device == "any" {
h.TPacket, err = afpacket.NewTPacket(
afpacket.OptFrameSize(snaplen),
afpacket.OptBlockSize(block_size),
afpacket.OptNumBlocks(num_blocks),
afpacket.OptPollTimeout(timeout))
} else {
h.TPacket, err = afpacket.NewTPacket(
afpacket.OptInterface(device),
afpacket.OptFrameSize(snaplen),
afpacket.OptBlockSize(block_size),
afpacket.OptNumBlocks(num_blocks),
afpacket.OptPollTimeout(timeout))
}
return h, err
}
func (h *afpacketHandle) ReadPacketData() (data []byte, ci gopacket.CaptureInfo, err error) {
return h.TPacket.ReadPacketData()
}
func (h *afpacketHandle) SetBPFFilter(expr string) (_ error) {
return h.TPacket.SetBPFFilter(expr)
}
func (h *afpacketHandle) Close() {
h.TPacket.Close()
}