本文整理匯總了Golang中C.pcap_findalldevs函數的典型用法代碼示例。如果您正苦於以下問題:Golang pcap_findalldevs函數的具體用法?Golang pcap_findalldevs怎麽用?Golang pcap_findalldevs使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了pcap_findalldevs函數的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
}
示例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
}
示例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
}
示例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
}