On 4/16/20 9:08 AM, Fernando Casas Schössow wrote:
Forgot to add the output of the equivalent virsh command for the same
VM:
Name MAC address Protocol Address
-------------------------------------------------------------------------------
lo 00:00:00:00:00:00 ipv4 127.0.0.1/8
lo 00:00:00:00:00:00 ipv6 ::1/128
eth0 52:54:00:12:b9:22 ipv4 192.168.7.31/26
eth0 52:54:00:12:b9:22 ipv6 fe80::5054:ff:fe12:b922/64
eth1 52:54:00:8e:b0:35 ipv4 192.168.1.34/24
eth1 52:54:00:8e:b0:35 ipv6 fe80::5054:ff:fe8e:b035/64
Thanks,
Fernando
On jue, abr 16, 2020 at 12:58 AM, Fernando Casas Schössow
<casasfernando(a)outlook.com> wrote:
> Hi,
>
> While using the function libvirt_domain_interface_addresses() with
> qemu guest agent as the source, for interfaces with more than one IP
> address, the function will only return one IP.
>
> Example code:
>
> $netdetails = libvirt_domain_interface_addresses($vmres, 2);
> foreach ($netdetails as $nic) {
> print_r($nic);
> }
>
>
> Example output:
>
> Array
> (
> [name] => eth0
> [hwaddr] => 52:54:00:12:b9:22
> [naddrs] => 2
> [addrs] => Array
> (
> [addr] => fe80::5054:ff:fe12:b922
> [prefix] => 64
> [type] => 1
> )
Ah, this is another clear bug in PHP bindings. The problem is we use
associative array for 'addrs'. As you can see, 'naddrs' is 2, so the API
returned 2 IP addresses (IPv4 and IPv6 ones). So we've constructed an
associative array for IPv4 and set $nic['addrs'] to it. Then we did the
same for IPv6. This is obviously wrong. Let me see if I can fix it.
Michal