Indy icon indicating copy to clipboard operation
Indy copied to clipboard

Getting loopback IP address from GetLocalAddressList.

Open coffeegreg opened this issue 2 years ago • 4 comments

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.

coffeegreg avatar Jul 21 '23 22:07 coffeegreg

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

rlebeau avatar Jul 24 '23 16:07 rlebeau

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.

coffeegreg avatar Jul 25 '23 10:07 coffeegreg

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.

rlebeau avatar Jul 25 '23 15:07 rlebeau

Good idea.

coffeegreg avatar Jul 25 '23 19:07 coffeegreg