mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
esx: switch esxUtil_ResolveHostname to return a new string
Change the interface of esxUtil_ResolveHostname() to return a newly allocated string with the result address, instead of forcing the callers to provide a buffer and its size. This way we can simply (auto)free the string, and make the function stacks smaller. Signed-off-by: Pino Toscano <ptoscano@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
parent
3aaf23ff69
commit
15914d0707
@ -602,7 +602,7 @@ esxConnectToHost(esxPrivate *priv,
|
|||||||
char **vCenterIPAddress)
|
char **vCenterIPAddress)
|
||||||
{
|
{
|
||||||
int result = -1;
|
int result = -1;
|
||||||
char ipAddress[NI_MAXHOST] = "";
|
g_autofree char *ipAddress = NULL;
|
||||||
char *username = NULL;
|
char *username = NULL;
|
||||||
char *password = NULL;
|
char *password = NULL;
|
||||||
char *url = NULL;
|
char *url = NULL;
|
||||||
@ -615,7 +615,7 @@ esxConnectToHost(esxPrivate *priv,
|
|||||||
|
|
||||||
ESX_VI_CHECK_ARG_LIST(vCenterIPAddress);
|
ESX_VI_CHECK_ARG_LIST(vCenterIPAddress);
|
||||||
|
|
||||||
if (esxUtil_ResolveHostname(conn->uri->server, ipAddress, NI_MAXHOST) < 0)
|
if (esxUtil_ResolveHostname(conn->uri->server, &ipAddress) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (conn->uri->user) {
|
if (conn->uri->user) {
|
||||||
@ -692,7 +692,7 @@ esxConnectToVCenter(esxPrivate *priv,
|
|||||||
const char *hostSystemIPAddress)
|
const char *hostSystemIPAddress)
|
||||||
{
|
{
|
||||||
int result = -1;
|
int result = -1;
|
||||||
char ipAddress[NI_MAXHOST] = "";
|
g_autofree char *ipAddress = NULL;
|
||||||
char *username = NULL;
|
char *username = NULL;
|
||||||
char *password = NULL;
|
char *password = NULL;
|
||||||
char *url = NULL;
|
char *url = NULL;
|
||||||
@ -704,7 +704,7 @@ esxConnectToVCenter(esxPrivate *priv,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (esxUtil_ResolveHostname(hostname, ipAddress, NI_MAXHOST) < 0)
|
if (esxUtil_ResolveHostname(hostname, &ipAddress) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (conn->uri->user) {
|
if (conn->uri->user) {
|
||||||
@ -813,7 +813,7 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
|
|||||||
virDrvOpenStatus result = VIR_DRV_OPEN_ERROR;
|
virDrvOpenStatus result = VIR_DRV_OPEN_ERROR;
|
||||||
esxPrivate *priv = NULL;
|
esxPrivate *priv = NULL;
|
||||||
char *potentialVCenterIPAddress = NULL;
|
char *potentialVCenterIPAddress = NULL;
|
||||||
char vCenterIPAddress[NI_MAXHOST] = "";
|
g_autofree char *vCenterIPAddress = NULL;
|
||||||
|
|
||||||
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
||||||
|
|
||||||
@ -875,16 +875,10 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virStrcpyStatic(vCenterIPAddress,
|
vCenterIPAddress = g_strdup(potentialVCenterIPAddress);
|
||||||
potentialVCenterIPAddress) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("vCenter IP address %s too big for destination"),
|
|
||||||
potentialVCenterIPAddress);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (esxUtil_ResolveHostname(priv->parsedUri->vCenter,
|
if (esxUtil_ResolveHostname(priv->parsedUri->vCenter,
|
||||||
vCenterIPAddress, NI_MAXHOST) < 0) {
|
&vCenterIPAddress) < 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,12 +278,12 @@ esxUtil_ParseDatastorePath(const char *datastorePath, char **datastoreName,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
esxUtil_ResolveHostname(const char *hostname,
|
esxUtil_ResolveHostname(const char *hostname, char **ipAddress)
|
||||||
char *ipAddress, size_t ipAddress_length)
|
|
||||||
{
|
{
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
struct addrinfo *result = NULL;
|
struct addrinfo *result = NULL;
|
||||||
int errcode;
|
int errcode;
|
||||||
|
g_autofree char *address = NULL;
|
||||||
|
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
|
|
||||||
@ -308,8 +308,9 @@ esxUtil_ResolveHostname(const char *hostname,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
errcode = getnameinfo(result->ai_addr, result->ai_addrlen, ipAddress,
|
address = g_new0(char, NI_MAXHOST);
|
||||||
ipAddress_length, NULL, 0, NI_NUMERICHOST);
|
errcode = getnameinfo(result->ai_addr, result->ai_addrlen, address,
|
||||||
|
NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
|
|
||||||
if (errcode != 0) {
|
if (errcode != 0) {
|
||||||
@ -319,6 +320,8 @@ esxUtil_ResolveHostname(const char *hostname,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*ipAddress = g_strdup(address);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,8 +55,7 @@ int esxUtil_ParseVirtualMachineIDString(const char *id_string, int *id);
|
|||||||
int esxUtil_ParseDatastorePath(const char *datastorePath, char **datastoreName,
|
int esxUtil_ParseDatastorePath(const char *datastorePath, char **datastoreName,
|
||||||
char **directoryName, char **directoryAndFileName);
|
char **directoryName, char **directoryAndFileName);
|
||||||
|
|
||||||
int esxUtil_ResolveHostname(const char *hostname,
|
int esxUtil_ResolveHostname(const char *hostname, char **ipAddress);
|
||||||
char *ipAddress, size_t ipAddress_length);
|
|
||||||
|
|
||||||
int esxUtil_ReformatUuid(const char *input, char *output);
|
int esxUtil_ReformatUuid(const char *input, char *output);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user