func main() { defer util.Run()() var ring *pfring.Ring var err error if ring, err = pfring.NewRing(*iface, uint32(*snaplen), pfring.FlagPromisc); err != nil { log.Fatalln("pfring ring creation error:", err) } if len(flag.Args()) > 0 { bpffilter := strings.Join(flag.Args(), " ") fmt.Fprintf(os.Stderr, "Using BPF filter %q\n", bpffilter) if err = ring.SetBPFFilter(bpffilter); err != nil { log.Fatalln("BPF filter error:", err) } } if *cluster >= 0 { if err = ring.SetCluster(*cluster, pfring.ClusterType(*clustertype)); err != nil { log.Fatalln("pfring SetCluster error:", err) } } if err = ring.SetSocketMode(pfring.ReadOnly); err != nil { log.Fatalln("pfring SetSocketMode error:", err) } else if err = ring.Enable(); err != nil { log.Fatalln("pfring Enable error:", err) } dumpcommand.Run(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 }