func (h *Hypervisor) GetDefinedInterfaces() ([]string, error) { number := C.virConnectNumOfDefinedInterfaces(h.cptr) if number == -1 { return nil, GetLastError() } names := make([]string, number) if number == 0 { return names, nil } cnames := make([]*C.char, number) result := C.virConnectListDefinedInterfaces(h.cptr, &cnames[0], number) if result == -1 { return nil, GetLastError() } for i, v := range cnames { names[i] = C.GoString(v) defer C.free(unsafe.Pointer(v)) } return names, nil }
func (c *VirConnection) ListDefinedInterfaces() ([]string, error) { const maxIfaces = 1024 var names [maxIfaces](*C.char) namesPtr := unsafe.Pointer(&names) numIfaces := C.virConnectListDefinedInterfaces( c.ptr, (**C.char)(namesPtr), maxIfaces) if numIfaces == -1 { return nil, GetLastError() } goNames := make([]string, numIfaces) for k := 0; k < int(numIfaces); k++ { goNames[k] = C.GoString(names[k]) C.free(unsafe.Pointer(names[k])) } return goNames, nil }