Hello!
Here http://godoc.org/code.google.com/p/gopacket/pfring I found this example:
if ring, err := pfring.NewRing("eth0", 65536, pfring.FlagPromisc); err != nil {
panic(err)
} else if err := ring.SetBPFFilter("tcp and port 80"); err != nil { // optional
panic(err)
} else if err := ring.Enable(); err != nil { // Must do this!, or you get no packets!
panic(err)
} else {
packetSource := gopacket.NewPacketSource(ring, gopacket.LinkTypeEthernet)
for packet := range packetSource.Packets() {
fmt.Println(packet)
//handlePacket(packet) // Do something with a packet here.
}
}
But it has one mistake which prevent correct compiling:
go build example.go
# command-line-arguments
./example.go:15: undefined: gopacket.LinkTypeEthernet
You should replace gopacket.LinkTypeEthernet by layers.LayerTypeEthernet and
add importing:
import "code.google.com/p/gopacket/layers"
After this fixes all works prefectly.
Thank you!
Original issue reported on code.google.com by pavel.odintsov on 15 Jun 2014 at 10:56
Original issue reported on code.google.com by
pavel.odintsov
on 15 Jun 2014 at 10:56