當前位置: 首頁>>代碼示例>>Golang>>正文


Golang C.pcap_close函數代碼示例

本文整理匯總了Golang中C.pcap_close函數的典型用法代碼示例。如果您正苦於以下問題:Golang pcap_close函數的具體用法?Golang pcap_close怎麽用?Golang pcap_close使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了pcap_close函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: OpenLive

// 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)
}
開發者ID:pombredanne,項目名稱:geard,代碼行數:34,代碼來源:pcap.go

示例2: Close

// 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()
	}
}
開發者ID:pote,項目名稱:golibpcap,代碼行數:8,代碼來源:pcap.go

示例3: Close

// 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()
}
開發者ID:ldnvnbl,項目名稱:gopacket,代碼行數:10,代碼來源:pcap.go

示例4: Close

func (p *Pcap) Close() {
	C.pcap_close(p.cptr)
}
開發者ID:dlintw,項目名稱:gopcap,代碼行數:3,代碼來源:pcap.go

示例5: CleanUp

// 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)
	}
}
開發者ID:donckers,項目名稱:gopacket,代碼行數:7,代碼來源:pcap.go

示例6: Close

// Close closes the underlying pcap handle.
func (p *Handle) Close() {
	C.pcap_close(p.cptr)
}
開發者ID:donckers,項目名稱:gopacket,代碼行數:4,代碼來源:pcap.go

示例7: Close

// Close the packet source.
func (h *Handle) Close() {
	C.pcap_close(h.pcap)
}
開發者ID:kelixin,項目名稱:go.pkt,代碼行數:4,代碼來源:capture.go

示例8: Close

func (p *Pcap) Close() error {
	// is there a possible error condition here?
	C.pcap_close(p.cptr)
	return nil
}
開發者ID:jvortega,項目名稱:mimir,代碼行數:5,代碼來源:pcap.go

示例9: Close

func (p *Pcap) Close() {
	C.pcap_close(p.pcap)
}
開發者ID:jasonish,項目名稱:dumpy,代碼行數:3,代碼來源:pcap.go


注:本文中的C.pcap_close函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。