// Apply the given filter it to the packet source. Only packets that match this // filter will be captured. func (h *Handle) ApplyFilter(filter *filter.Filter) error { if !filter.Validate() { return fmt.Errorf("Invalid filter") } h.filter = filter return nil }
// Apply the given filter it to the packet source. Only packets that match this // filter will be captured. func (h *Handle) ApplyFilter(filter *filter.Filter) error { if !filter.Validate() { return fmt.Errorf("Invalid filter") } err_str := (*C.char)(C.calloc(256, 1)) defer C.free(unsafe.Pointer(err_str)) dev_str := C.CString(h.Device) defer C.free(unsafe.Pointer(dev_str)) err := C.pcap_setfilter(h.pcap, (*C.struct_bpf_program)(filter.Program())) if err < 0 { return fmt.Errorf("Could not set filter: %s", h.get_error()) } return nil }