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


Golang C.pcap_activate函數代碼示例

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


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

示例1: Activate

// Activate should only be called on a Pcap that was obtained through Create.
func (p *Pcap) Activate() error {
	res := int32(C.pcap_activate(p.cptr))
	if res < 0 {
		return fmt.Errorf("%s(errnum=%d)", Statustostr(res), res)
	}
	return nil
}
開發者ID:pote,項目名稱:golibpcap,代碼行數:8,代碼來源:pcap.go

示例2: Activate

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

示例3: Activate

// Activate activates the handle.  The current InactiveHandle becomes invalid
// and all future function calls on it will fail.
func (p *InactiveHandle) Activate() (*Handle, error) {
	err := activateError(C.pcap_activate(p.cptr))
	if err != aeNoError {
		return nil, err
	}
	h := &Handle{cptr: p.cptr, device: p.device, blockForever: p.blockForever}
	p.cptr = nil
	return h, nil
}
開發者ID:donckers,項目名稱:gopacket,代碼行數:11,代碼來源:pcap.go

示例4: main

func main() {
	var errbuf = (*C.char)(C.malloc(C.PCAP_ERRBUF_SIZE))
	defer C.free(unsafe.Pointer(errbuf))
	var source = C.CString("any")
	defer C.free(unsafe.Pointer(source))

	pcap_handle := C.pcap_create(source, errbuf)
	if pcap_handle == nil {
		panic("pcap_handle")
	}
	C.pcap_set_buffer_size(pcap_handle, 2*1024*1024)
	C.pcap_set_promisc(pcap_handle, 1)
	C.pcap_set_snaplen(pcap_handle, 512) // more than enough to recognize a WOL packet
	C.pcap_setdirection(pcap_handle, C.PCAP_D_IN)
	if C.pcap_activate(pcap_handle) != 0 {
		panic(C.GoString(C.pcap_geterr(pcap_handle)))
	}

	var bpf_program C.struct_bpf_program
	if C.pcap_compile(pcap_handle, &bpf_program, pcap_filter, 0, 0) != 0 {
		panic(C.GoString(C.pcap_geterr(pcap_handle)))
	}
	if C.pcap_setfilter(pcap_handle, &bpf_program) != 0 {
		panic(C.GoString(C.pcap_geterr(pcap_handle)))
	}

	for {
		var pkt_header *C.struct_pcap_pkthdr
		var pkt_data *C.u_char
		if C.pcap_next_ex(pcap_handle, &pkt_header, &pkt_data) < 0 {
			panic(C.GoString(C.pcap_geterr(pcap_handle)))
		}
		if pkt_data == nil {
			continue
		}
		data := make([]byte, pkt_header.caplen)
		copy(data, (*(*[10000000]byte)(unsafe.Pointer(pkt_data)))[0:])
		from_mac, to_mac := checkwol(data)
		if from_mac != "" {
			fmt.Printf("%v: %v sends WOL to %v\n", time.Now(), from_mac, to_mac)
		}
	}

}
開發者ID:chrlutz,項目名稱:limux-gosa,代碼行數:44,代碼來源:wollist.go

示例5: Activate

// Activate a packet capture handle to look at packets on the network, with the options that
// were set on the handle being in effect.
func (p *Pcap) Activate() error {
	if C.pcap_activate(p.cptr) != 0 {
		return p.Geterror()
	}
	return nil
}
開發者ID:ThomsonReutersEikon,項目名稱:pcap,代碼行數:8,代碼來源:pcap.go

示例6: activation

func (p *Handle) activation() {
	C.pcap_activate(p.cptr)
}
開發者ID:pombredanne,項目名稱:geard,代碼行數:3,代碼來源:pcap.go


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