Open coffeegreg opened 11 months ago
Is there a particular reason why the loopback IP should be included?
It is just a question... Sometimes it is necessary to run services listening on loopback interface addresses such as 127.0.0.1, although there may be more interfaces and loopback IP addresses. Mainly for diagnostics and troubleshooting, but also for interconnecting local services that listening on loopback interfaces only. Before trying to run a service on a given interface, it would be good to check if it exists. I can imagine a machine with multiple loopback interfaces and/or multiple IP addresses on them, or even in extreme cases no loopback interface at all. This is where the GetLocalAddressList procedure could come in handy if it didn't filter out IP addresses from the loopback interfaces. As I mentioned, this is just a question to find out more about possible issues that may have caused the intentional loopback IP address filtering out in the GetLocalAddressList routine.
There is not a technical reason why loopback addresses are being filtered out, other than it's not common to have a server listening on loopbacks. I suppose I could add an input flag to GetLocalAddressList()
to let the caller specify whether loopbacks should be included in the output or not.
Good idea.
Does anyone know why the loopback IP address (127.0.0.1) is intentionally filtered out in the procedures: 1) TIdStackUnix.GetLocalAddressList
if (LAddrInfo^.ifa_addr <> nil) and ((LAddrInfo^.ifa_flags and IFF_LOOPBACK) = 0) then
2) TIdStackWindows.GetLocalAddressList in GetLocalAddressesByAdaptersAddressesif (Adapter.IfType <> IF_TYPE_SOFTWARE_LOOPBACK) and ((Adapter.Flags and IP_ADAPTER_RECEIVE_ONLY) = 0) then
? Without these conditions, it correctly fetches all IP addresses, including the loopback IP address. Tested on Windows, Linux and macOS.