Ejemplo n.º 1
0
func (h *Hypervisor) ListInterfaces(flags uint) ([]*Interface, error) {
	var cinterfaces *C.virInterfacePtr
	result := C.virConnectListAllInterfaces(h.cptr, &cinterfaces, C.uint(flags))
	if result == -1 {
		return nil, GetLastError()
	}

	var interfaces = make([]*Interface, result)
	p := (*[1 << 30]C.virInterfacePtr)(unsafe.Pointer(cinterfaces))

	for i := 0; i < int(result); i++ {
		interfaces[i] = newInterface(p[i])
	}
	defer C.free(unsafe.Pointer(cinterfaces))

	return interfaces, nil
}
Ejemplo n.º 2
0
func (c *VirConnection) ListAllInterfaces(flags uint32) ([]VirInterface, error) {
	var cList *C.virInterfacePtr
	numIfaces := C.virConnectListAllInterfaces(c.ptr, (**C.virInterfacePtr)(&cList), C.uint(flags))
	if numIfaces == -1 {
		return nil, GetLastError()
	}
	hdr := reflect.SliceHeader{
		Data: uintptr(unsafe.Pointer(cList)),
		Len:  int(numIfaces),
		Cap:  int(numIfaces),
	}
	var ifaces []VirInterface
	slice := *(*[]C.virInterfacePtr)(unsafe.Pointer(&hdr))
	for _, ptr := range slice {
		ifaces = append(ifaces, VirInterface{ptr})
	}
	C.free(unsafe.Pointer(cList))
	return ifaces, nil
}