virSocketAddr addr;
virSocketAddrPtr addrptr = NULL;
char *dev_name = NULL;
@@ -4566,12 +4567,12 @@ networkGetNetworkAddress(const char *netname, char **netaddr)
case VIR_NETWORK_FORWARD_NONE:
case VIR_NETWORK_FORWARD_NAT:
case VIR_NETWORK_FORWARD_ROUTE:
- /* if there's an ipv4def, get it's address */
- ipdef = virNetworkDefGetIpByIndex(netdef, AF_INET, 0);
+ /* if there's an ipdef, get it's IPv4 or IPv6 address */
+ ipdef = virNetworkDefGetIpByIndex(netdef, want_ipv6 ? AF_INET6 : AF_INET, 0);
if (!ipdef) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("network '%s' doesn't have an IPv4 address"),
- netdef->name);
+ _("network '%s' doesn't have an '%s' address"),
+ netdef->name, want_ipv6 ? "IPv6" : "IPv4");
break;
}
addrptr = &ipdef->address;
@@ -4599,7 +4600,7 @@ networkGetNetworkAddress(const char *netname, char **netaddr)
}
if (dev_name) {
- if (virNetDevGetIPv4Address(dev_name, &addr) < 0)
+ if (virNetDevGetIPAddress(dev_name, want_ipv6, &addr) < 0)
goto error;
addrptr = &addr;
}
diff --git a/src/network/bridge_driver.h b/src/network/bridge_driver.h
index 2f801ee..465ab18 100644
--- a/src/network/bridge_driver.h
+++ b/src/network/bridge_driver.h
@@ -44,7 +44,9 @@ int networkReleaseActualDevice(virDomainDefPtr dom,
virDomainNetDefPtr iface)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
-int networkGetNetworkAddress(const char *netname, char **netaddr)
+int networkGetNetworkAddress(const char *netname,
+ char **netaddr,
+ bool want_ipv6)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int networkDnsmasqConfContents(virNetworkObjPtr network,
@@ -57,7 +59,7 @@ int networkDnsmasqConfContents(virNetworkObjPtr network,
# define networkAllocateActualDevice(dom, iface) 0
# define networkNotifyActualDevice(dom, iface) (dom=dom, iface=iface, 0)
# define networkReleaseActualDevice(dom, iface) (dom=dom, iface=iface, 0)
-# define networkGetNetworkAddress(netname, netaddr) (-2)
+# define networkGetNetworkAddress(netname, netaddr, want_ipv6) (-2)
# define networkDnsmasqConfContents(network, pidfile, configstr, \
dctx, caps) 0
# endif
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 24b2ad9..82a4ce3 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7286,7 +7286,9 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg,
listenNetwork = virDomainGraphicsListenGetNetwork(graphics, 0);
if (!listenNetwork)
break;
- ret = networkGetNetworkAddress(listenNetwork, &netAddr);
+ ret = networkGetNetworkAddress(listenNetwork, &netAddr,
+ graphics->listens->family ==
+ VIR_DOMAIN_GRAPHICS_LISTEN_FAMILY_IPV6);
if (ret <= -2) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s", _("network-based listen not possible, "
@@ -7450,7 +7452,9 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
listenNetwork = virDomainGraphicsListenGetNetwork(graphics, 0);
if (!listenNetwork)
break;
- ret = networkGetNetworkAddress(listenNetwork, &netAddr);
+ ret = networkGetNetworkAddress(listenNetwork, &netAddr,
+ graphics->listens->family ==
+ VIR_DOMAIN_GRAPHICS_LISTEN_FAMILY_IPV6);
if (ret <= -2) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s", _("network-based listen not possible, "