mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00: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)
|
||||
{
|
||||
int result = -1;
|
||||
char ipAddress[NI_MAXHOST] = "";
|
||||
g_autofree char *ipAddress = NULL;
|
||||
char *username = NULL;
|
||||
char *password = NULL;
|
||||
char *url = NULL;
|
||||
@ -615,7 +615,7 @@ esxConnectToHost(esxPrivate *priv,
|
||||
|
||||
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;
|
||||
|
||||
if (conn->uri->user) {
|
||||
@ -692,7 +692,7 @@ esxConnectToVCenter(esxPrivate *priv,
|
||||
const char *hostSystemIPAddress)
|
||||
{
|
||||
int result = -1;
|
||||
char ipAddress[NI_MAXHOST] = "";
|
||||
g_autofree char *ipAddress = NULL;
|
||||
char *username = NULL;
|
||||
char *password = NULL;
|
||||
char *url = NULL;
|
||||
@ -704,7 +704,7 @@ esxConnectToVCenter(esxPrivate *priv,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (esxUtil_ResolveHostname(hostname, ipAddress, NI_MAXHOST) < 0)
|
||||
if (esxUtil_ResolveHostname(hostname, &ipAddress) < 0)
|
||||
return -1;
|
||||
|
||||
if (conn->uri->user) {
|
||||
@ -813,7 +813,7 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
|
||||
virDrvOpenStatus result = VIR_DRV_OPEN_ERROR;
|
||||
esxPrivate *priv = NULL;
|
||||
char *potentialVCenterIPAddress = NULL;
|
||||
char vCenterIPAddress[NI_MAXHOST] = "";
|
||||
g_autofree char *vCenterIPAddress = NULL;
|
||||
|
||||
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
||||
|
||||
@ -875,16 +875,10 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virStrcpyStatic(vCenterIPAddress,
|
||||
potentialVCenterIPAddress) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("vCenter IP address %s too big for destination"),
|
||||
potentialVCenterIPAddress);
|
||||
goto cleanup;
|
||||
}
|
||||
vCenterIPAddress = g_strdup(potentialVCenterIPAddress);
|
||||
} else {
|
||||
if (esxUtil_ResolveHostname(priv->parsedUri->vCenter,
|
||||
vCenterIPAddress, NI_MAXHOST) < 0) {
|
||||
&vCenterIPAddress) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -278,12 +278,12 @@ esxUtil_ParseDatastorePath(const char *datastorePath, char **datastoreName,
|
||||
|
||||
|
||||
int
|
||||
esxUtil_ResolveHostname(const char *hostname,
|
||||
char *ipAddress, size_t ipAddress_length)
|
||||
esxUtil_ResolveHostname(const char *hostname, char **ipAddress)
|
||||
{
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *result = NULL;
|
||||
int errcode;
|
||||
g_autofree char *address = NULL;
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
|
||||
@ -308,8 +308,9 @@ esxUtil_ResolveHostname(const char *hostname,
|
||||
return -1;
|
||||
}
|
||||
|
||||
errcode = getnameinfo(result->ai_addr, result->ai_addrlen, ipAddress,
|
||||
ipAddress_length, NULL, 0, NI_NUMERICHOST);
|
||||
address = g_new0(char, NI_MAXHOST);
|
||||
errcode = getnameinfo(result->ai_addr, result->ai_addrlen, address,
|
||||
NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
||||
freeaddrinfo(result);
|
||||
|
||||
if (errcode != 0) {
|
||||
@ -319,6 +320,8 @@ esxUtil_ResolveHostname(const char *hostname,
|
||||
return -1;
|
||||
}
|
||||
|
||||
*ipAddress = g_strdup(address);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -55,8 +55,7 @@ int esxUtil_ParseVirtualMachineIDString(const char *id_string, int *id);
|
||||
int esxUtil_ParseDatastorePath(const char *datastorePath, char **datastoreName,
|
||||
char **directoryName, char **directoryAndFileName);
|
||||
|
||||
int esxUtil_ResolveHostname(const char *hostname,
|
||||
char *ipAddress, size_t ipAddress_length);
|
||||
int esxUtil_ResolveHostname(const char *hostname, char **ipAddress);
|
||||
|
||||
int esxUtil_ReformatUuid(const char *input, char *output);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user