Skip to content

Instantly share code, notes, and snippets.

@millken
Forked from cjoudrey/bpf.go
Created January 26, 2018 15:51
Show Gist options
  • Save millken/d9c3a63662911438a04f99616b2b1506 to your computer and use it in GitHub Desktop.
Save millken/d9c3a63662911438a04f99616b2b1506 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/google/gopacket"
"github.com/google/gopacket/pcap"
)
func main() {
handle, err := pcap.OpenLive("en0", 1600, true, pcap.BlockForever)
if err != nil {
panic(err)
}
bpfInstructions := []pcap.BPFInstruction{
{0x28, 0, 0, 0x0000000c},
{0x15, 0, 10, 0x00000800},
{0x30, 0, 0, 0x00000017},
{0x15, 0, 8, 0x00000006},
{0x28, 0, 0, 0x00000014},
{0x45, 6, 0, 0x00001fff},
{0xb1, 0, 0, 0x0000000e},
{0x48, 0, 0, 0x0000000e},
{0x15, 2, 0, 0x00000050},
{0x48, 0, 0, 0x00000010},
{0x15, 0, 1, 0x00000050},
{0x6, 0, 0, 0x00040000},
{0x6, 0, 0, 0x00000000},
}
if err := handle.SetBPFInstructionFilter(bpfInstructions); err != nil {
panic(err)
}
packetSource := gopacket.NewPacketSource(handle, handle.LinkType())
for packet := range packetSource.Packets() {
fmt.Printf("%s", packet.Dump())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment