mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 15:15:25 +00:00
qemuAgentGetInterfaceAddresses: turn ifname into char*
We only care about the first part of the 'ifname' string, splitting it is overkill. Instead, just replace the ':' with a '\0' in a copy of the string. This reduces the count of the varaibles containing some form of the interface name to two. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com> Reviewed-by: Neal Gompa <ngompa13@gmail.com>
This commit is contained in:
parent
ddc2e51767
commit
3b9432fa28
@ -2129,9 +2129,9 @@ qemuAgentGetInterfaceAddresses(virDomainInterfacePtr **ifaces_ret,
|
|||||||
virJSONValuePtr tmp_iface)
|
virJSONValuePtr tmp_iface)
|
||||||
{
|
{
|
||||||
virJSONValuePtr ip_addr_arr = NULL;
|
virJSONValuePtr ip_addr_arr = NULL;
|
||||||
const char *hwaddr, *ifname_s, *name = NULL;
|
const char *hwaddr, *name = NULL;
|
||||||
virDomainInterfacePtr iface = NULL;
|
virDomainInterfacePtr iface = NULL;
|
||||||
g_auto(GStrv) ifname = NULL;
|
g_autofree char *ifname = NULL;
|
||||||
size_t addrs_count = 0;
|
size_t addrs_count = 0;
|
||||||
size_t j;
|
size_t j;
|
||||||
|
|
||||||
@ -2144,10 +2144,9 @@ qemuAgentGetInterfaceAddresses(virDomainInterfacePtr **ifaces_ret,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Handle interface alias (<ifname>:<alias>) */
|
/* Handle interface alias (<ifname>:<alias>) */
|
||||||
ifname = virStringSplit(name, ":", 2);
|
ifname = g_strdelimit(g_strdup(name), ":", '\0');
|
||||||
ifname_s = ifname[0];
|
|
||||||
|
|
||||||
iface = virHashLookup(ifaces_store, ifname_s);
|
iface = virHashLookup(ifaces_store, ifname);
|
||||||
|
|
||||||
/* If the hash table doesn't contain this iface, add it */
|
/* If the hash table doesn't contain this iface, add it */
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
@ -2157,11 +2156,11 @@ qemuAgentGetInterfaceAddresses(virDomainInterfacePtr **ifaces_ret,
|
|||||||
iface = g_new0(virDomainInterface, 1);
|
iface = g_new0(virDomainInterface, 1);
|
||||||
(*ifaces_ret)[*ifaces_count - 1] = iface;
|
(*ifaces_ret)[*ifaces_count - 1] = iface;
|
||||||
|
|
||||||
if (virHashAddEntry(ifaces_store, ifname_s, iface) < 0)
|
if (virHashAddEntry(ifaces_store, ifname, iface) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
iface->naddrs = 0;
|
iface->naddrs = 0;
|
||||||
iface->name = g_strdup(ifname_s);
|
iface->name = g_strdup(ifname);
|
||||||
|
|
||||||
hwaddr = virJSONValueObjectGetString(tmp_iface, "hardware-address");
|
hwaddr = virJSONValueObjectGetString(tmp_iface, "hardware-address");
|
||||||
iface->hwaddr = g_strdup(hwaddr);
|
iface->hwaddr = g_strdup(hwaddr);
|
||||||
|
Loading…
Reference in New Issue
Block a user