作者:pombredann
项目:gear
// OpenLive opens a device and returns a *Handle.
// It takes as arguments the name of the device ("eth0"), the maximum size to
// read for each packet (snaplen), whether to put the interface in promiscuous
// mode, and a timeout.
func OpenLive(device string, snaplen int32, promisc bool, timeout time.Duration) (handle *Handle, _ error) {
var buf *C.char
buf = (*C.char)(C.calloc(errorBufferSize, 1))
defer C.free(unsafe.Pointer(buf))
var pro C.int
if promisc {
pro = 1
}
dev := C.CString(device)
defer C.free(unsafe.Pointer(dev))
// This copies a bunch of the pcap_open_live implementation from pcap.c:
cptr := C.pcap_create(dev, buf)
if cptr == nil {
return nil, errors.New(C.GoString(buf))
}
var status C.int
if status = C.pcap_set_snaplen(cptr, C.int(snaplen)); status < 0 {
goto fail
} else if status = C.pcap_set_promisc(cptr, pro); status < 0 {
goto fail
} else if status = C.pcap_set_timeout(cptr, C.int(timeout/time.Millisecond)); status < 0 {
goto fail
}
return newHandle(cptr), nil
fail:
C.pcap_close(cptr)
return nil, statusError(status)
}
作者:pot
项目:golibpca
// Close closes the files associated with p and deallocates C resources.
func (p *Pcap) Close() {
if p.cptr != nil {
p.m.Lock()
C.pcap_close(p.cptr)
p.m.Unlock()
}
}
作者:ldnvnb
项目:gopacke
// Close closes the underlying pcap handle.
func (p *Handle) Close() {
p.mu.Lock()
if p.cptr == nil {
return
}
C.pcap_close(p.cptr)
p.cptr = nil
p.mu.Unlock()
}
作者:dlint
项目:gopca
func (p *Pcap) Close() {
C.pcap_close(p.cptr)
}
作者:doncker
项目:gopacke
// CleanUp cleans up any stuff left over from a successful or failed building
// of a handle.
func (p *InactiveHandle) CleanUp() {
if p.cptr != nil {
C.pcap_close(p.cptr)
}
}
作者:doncker
项目:gopacke
// Close closes the underlying pcap handle.
func (p *Handle) Close() {
C.pcap_close(p.cptr)
}
作者:kelixi
项目:go.pk
// Close the packet source.
func (h *Handle) Close() {
C.pcap_close(h.pcap)
}
作者:jvorteg
项目:mimi
func (p *Pcap) Close() error {
// is there a possible error condition here?
C.pcap_close(p.cptr)
return nil
}
作者:jasonis
项目:dump
func (p *Pcap) Close() {
C.pcap_close(p.pcap)
}