interfaces: Fix fetching of interfaces on Win32
authorNirbheek Chauhan <nirbheek@centricular.com>
Thu, 9 Jul 2020 12:25:53 +0000 (17:55 +0530)
committerNirbheek Chauhan <nirbheek@centricular.com>
Thu, 9 Jul 2020 17:30:27 +0000 (23:00 +0530)
commit79dae65b754cedf276d4010a5e4c35059477bca3
tree692712aa356a15de470b815a56ad66f0952cb4d3
parent5b29ca210560cc785a659e679f114057bcf53753
interfaces: Fix fetching of interfaces on Win32

nice_interfaces_get_local_interfaces() was returning the hardware
device names of interfaces that have been seen in the past or could be
connected. It had no relation to the actual interfaces present on the
device. Perhaps this worked back in the XP days, but it is returning
garbage today.

Use GetAdapterAddresses(), and return the adapter friendly names as
the interface names. At the same time, update
nice_interfaces_get_ip_for_interface() to match.

Coincidentally, this also fixes UWP compatibility since GetIfTable and
GetIpAddrTable are not available when targeting UWP. They are only
available for desktop apps:

https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getiftable
https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getipaddrtable
agent/interfaces.c