mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 18:20:27 +00:00
25 lines
493 B
Go
25 lines
493 B
Go
package sniff
|
|
|
|
import (
|
|
"github.com/google/gopacket"
|
|
"github.com/google/gopacket/pcap"
|
|
)
|
|
|
|
// Source describes a packet data source that can be terminated.
|
|
type Source interface {
|
|
gopacket.ZeroCopyPacketDataSource
|
|
Close()
|
|
}
|
|
|
|
const (
|
|
snaplen = 65535
|
|
promisc = true
|
|
timeout = pcap.BlockForever
|
|
)
|
|
|
|
// NewSource returns a live packet data source via the passed device
|
|
// (interface).
|
|
func NewSource(device string) (Source, error) {
|
|
return pcap.OpenLive(device, snaplen, promisc, timeout)
|
|
}
|