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


Golang C.pcap_freealldevs函數代碼示例

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


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

示例1: Findalldevs

func Findalldevs() (ifs []Interface, err error) {
	var buf *C.char
	buf = (*C.char)(C.calloc(ERRBUF_SIZE, 1))
	defer C.free(unsafe.Pointer(buf))
	var alldevsp *C.pcap_if_t

	if -1 == C.pcap_findalldevs((**C.pcap_if_t)(&alldevsp), buf) {
		return nil, errors.New(C.GoString(buf))
	}
	defer C.pcap_freealldevs((*C.pcap_if_t)(alldevsp))
	dev := alldevsp
	var i uint32
	for i = 0; dev != nil; dev = (*C.pcap_if_t)(dev.next) {
		i++
	}
	ifs = make([]Interface, i)
	dev = alldevsp
	for j := uint32(0); dev != nil; dev = (*C.pcap_if_t)(dev.next) {
		var iface Interface
		iface.Name = C.GoString(dev.name)
		iface.Description = C.GoString(dev.description)
		iface.Addresses = findalladdresses(dev.addresses)
		// TODO: add more elements
		ifs[j] = iface
		j++
	}
	return
}
開發者ID:dlintw,項目名稱:gopcap,代碼行數:28,代碼來源:pcap.go

示例2: GetDeviceList

func GetDeviceList() ([]string, error) {
	var ifs []string
	var buf *C.char
	buf = (*C.char)(C.calloc(ERRBUF_SIZE, 1))
	defer C.free(unsafe.Pointer(buf))

	var devs *C.pcap_if_t
	if C.pcap_findalldevs((**C.pcap_if_t)(&devs), buf) == -1 {
		return nil, errors.New(C.GoString(buf))
	}
	defer C.pcap_freealldevs((*C.pcap_if_t)(devs))
	dev := devs
	var devcount uint32

	// figure out how many devices we have available
	for devcount = 0; dev != nil; dev = (*C.pcap_if_t)(dev.next) {
		devcount++
	}

	dev = devs
	for i := uint32(0); dev != nil; dev = (*C.pcap_if_t)(dev.next) {
		ifs = append(ifs, C.GoString(dev.name))
		i++
	}
	return ifs, nil
}
開發者ID:jvortega,項目名稱:mimir,代碼行數:26,代碼來源:pcap.go

示例3: Findalldevs

func Findalldevs() (ifs []Interface, err os.Error) {
	var alldevsp *C.pcap_if_t
	var buf [ERRBUF_SIZE]byte
	cbuf := (*C.char)(unsafe.Pointer(&buf[0]))

	if C.pcap_findalldevs(&alldevsp, cbuf) == -1 {
		clen := C.strlen(cbuf)
		err = os.NewError(string(buf[:clen]))
		return
	}
	defer C.pcap_freealldevs(alldevsp)

	dev := (*C.struct_pcap_if)(alldevsp)
	i := 0
	for ; dev != nil; dev = dev.next {
		i++
	}

	ifs = make([]Interface, i)
	for ; dev != nil; dev = dev.next {
		ifs[i].Name = C.GoString(dev.name)
		ifs[i].Desc = C.GoString(dev.description)
		i++
	}

	return
}
開發者ID:alvinlee,項目名稱:gopcap,代碼行數:27,代碼來源:pcap.go

示例4: Findalldevs

func Findalldevs() (ifs []Interface, err string) {
	var buf *C.char
	buf = (*C.char)(C.calloc(ERRBUF_SIZE, 1))
	var alldevsp *C.struct_pcap_if

	if -1 == C.pcap_findalldevs((**C.pcap_if_t)(unsafe.Pointer(&alldevsp)), buf) {
		ifs = nil
		err = C.GoString(buf)
	} else {
		dev := alldevsp
		var i uint32
		for i = 0; dev != nil; dev = dev.next {
			i++
		}
		ifs = make([]Interface, i)
		dev = alldevsp
		for j := uint32(0); dev != nil; dev = dev.next {
			var iface Interface
			iface.Name = C.GoString(dev.name)
			iface.Description = C.GoString(dev.description)
			// TODO: add more elements
			ifs[j] = iface
			j++
		}
		C.pcap_freealldevs((*C.pcap_if_t)(alldevsp))
	}
	C.free(unsafe.Pointer(buf))
	return
}
開發者ID:sungit,項目名稱:gopcap,代碼行數:29,代碼來源:pcap.go


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