IndySockets / Indy

Indy - Internet Direct
https://www.indyproject.org
434 stars 147 forks source link

Getting loopback IP address from GetLocalAddressList. #494

Open coffeegreg opened 11 months ago

coffeegreg commented 11 months ago

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 GetLocalAddressesByAdaptersAddresses if (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.

rlebeau commented 11 months ago

Is there a particular reason why the loopback IP should be included?

coffeegreg commented 11 months ago

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.

rlebeau commented 11 months ago

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.

coffeegreg commented 11 months ago

Good idea.