func (h *Handle) Activate() error {
    err := C.pcap_activate(h.pcap)
    if err < 0 {
        return fmt.Errorf("Could not activate: %s", h.get_error())
    }
    return nil
}
Activate the packet source. Note that after calling this method it will not
be possible to change the packet source configuration (MTU, promiscuous mode,
monitor mode, ...)
package pcap
import "C"
import "fmt"
import "unsafe"
import "github.com/ghedo/go.pkt/filter"
import "github.com/ghedo/go.pkt/packet"
type Handle struct {
    Device string
    pcap   *C.pcap_t
}
func Open(dev_name string) (*Handle, error) {
    handle := &Handle{ Device: dev_name }
    dev_str := C.CString(dev_name)
    defer C.free(unsafe.Pointer(dev_str))
    err_str := (*C.char)(C.calloc(256, 1))
    defer C.free(unsafe.Pointer(err_str))
    handle.pcap = C.pcap_create(dev_str, err_str)
    if handle == nil {
        return nil, fmt.Errorf(
            "Could not open device: %s", C.GoString(err_str),
        )
    }
    return handle, nil
}
func (h *Handle) LinkType() packet.Type {
    return packet.LinkType(uint32(C.pcap_datalink(h.pcap)))
}
func (h *Handle) SetMTU(mtu int) error {
    err := C.pcap_set_snaplen(h.pcap, C.int(mtu))
    if err < 0 {
        return fmt.Errorf("Handle already active")
    }
    return nil
}
func (h *Handle) SetPromiscMode(promisc bool) error {
    var promisc_int C.int
    if promisc {
        promisc_int = 1
    } else {
        promisc_int = 0
    }
    err := C.pcap_set_promisc(h.pcap, promisc_int)
    if err < 0 {
        return fmt.Errorf("Handle already active")
    }
    return nil
}
func (h *Handle) SetMonitorMode(monitor bool) error {
    var rfmon_int C.int
    if monitor {
        rfmon_int = 1
    } else {
        rfmon_int = 0
    }
    err := C.pcap_set_rfmon(h.pcap, rfmon_int)
    if err < 0 {
        return fmt.Errorf("Handle already active")
    }
    return nil
}
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
}