本文整理匯總了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)
}
示例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()
}
}
示例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()
}
示例4: Close
func (p *Pcap) Close() {
C.pcap_close(p.cptr)
}
示例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)
}
}
示例6: Close
// Close closes the underlying pcap handle.
func (p *Handle) Close() {
C.pcap_close(p.cptr)
}
示例7: Close
// Close the packet source.
func (h *Handle) Close() {
C.pcap_close(h.pcap)
}
示例8: Close
func (p *Pcap) Close() error {
// is there a possible error condition here?
C.pcap_close(p.cptr)
return nil
}
示例9: Close
func (p *Pcap) Close() {
C.pcap_close(p.pcap)
}