コード例 #1
0
ファイル: pcap.go プロジェクト: pombredanne/geard
// 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)
}
コード例 #2
0
ファイル: pcap.go プロジェクト: pote/golibpcap
// 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()
	}
}
コード例 #3
0
ファイル: pcap.go プロジェクト: ldnvnbl/gopacket
// 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()
}
コード例 #4
0
ファイル: pcap.go プロジェクト: dlintw/gopcap
func (p *Pcap) Close() {
	C.pcap_close(p.cptr)
}
コード例 #5
0
ファイル: pcap.go プロジェクト: donckers/gopacket
// 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)
	}
}
コード例 #6
0
ファイル: pcap.go プロジェクト: donckers/gopacket
// Close closes the underlying pcap handle.
func (p *Handle) Close() {
	C.pcap_close(p.cptr)
}
コード例 #7
0
ファイル: capture.go プロジェクト: kelixin/go.pkt
// Close the packet source.
func (h *Handle) Close() {
	C.pcap_close(h.pcap)
}
コード例 #8
0
ファイル: pcap.go プロジェクト: jvortega/mimir
func (p *Pcap) Close() error {
	// is there a possible error condition here?
	C.pcap_close(p.cptr)
	return nil
}
コード例 #9
0
ファイル: pcap.go プロジェクト: jasonish/dumpy
func (p *Pcap) Close() {
	C.pcap_close(p.pcap)
}