Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GStack.LocalAddress returns empty only with Delphi 10
#1
Hello,

I use UDP to send a  video stream to VLC, it works very well when I have a local network active (Wifi or Ethernet).
But if I have no Wifi and no Ethernet card activated, it works if I compile my source code using Delphi2010 ( using 127.0.0.1 IP address) but doesn’t work if I compile my source code using Delphi 10.
After searching, I discover that  my procedure to find local IP can find 127.0.0.1 ( Nbr of local IP =1) using Delphi 2010 but find no local IP using Delphi 10 (Nbr of local IP = 0)

Code:
TIdStack.IncUsage;  LocalIPasked := '0.0.0.0';
  try    //**************************************************************
    NbLocalIP := GStack.LocalAddresses.Count;
    Memo1.Lines.Add(Format('nbr of local IP= %d ', [NbLocalIP]));
    for i := 0 to NbLocalIP-1 do
      begin
        Memo1.Lines.Add(Format('IP n° %d = %s', [i + 1, GStack.LocalAddresses[i]]));
      end;
  finally
    TIdStack.DecUsage;
  end;

 
Why do I have this difference between Delphi2010 and Delphi_10 ? Have I miss something or compiler setup when I change my Delphi 2010 to Delphi 10?


Rem: I have tested also a second way to find the number of local IP but same result (0) using Delphi 10


Code:
...
LList := TIdStackLocalAddressList.Create;
  try
    GStack.GetLocalAddressList(LList);
    Memo1.Lines.Add(Format('nbr of local IP found: %d ', [LList.Count]));
...

Result is 0 using Delphi 10

Can someone tell me where I miss something?
Thank you.
Reply
#2
Are you using these on the same machine? I dont think this is a difference between compiler versions.

Unless something has changed (and I have not looked at this in a long time since networking is now pervasive) if there are NO network adapters available, 127.0.0.1 will not be usable. You need at *least* one active networking adapter.

It is possible this has changed, it has been a very long time since I've needed to work on a machine with no network adapter at all. In such cases the solution used to be to install the Microsoft Network Loopback adapter which is part of Windows but must be manually added. This is a "dummy" network card that provides for local access using 127.0.0.1 when no physical networks exist.

https://www.youtube.com/watch?v=0HEhLsnHsdA
Reply
#3
Thank you Kutzu for your answer.

Yes it is on the same PC: this computer has an Ethernet card and a Wifi Dungle.
As usual, when I send data using multicast UDP, I must indicate the UDP address and port and indicate the Interface IP used. it can be the Wifi card or the Ethernet card.
If I unplug only one of the 2 IP interfaces I have, I continue to work without the need of 127.0.0.1
but if I unplug the Wifi dungle, and unplug the Ethernet cable, when I use the same Source compiled with Delphi 2010 and Delphi XE10, only the software compiled with Delphi 2010 can find 127.0.0.1

And I can say that without any IP interface, Using 127.0.0.1 let me send video stream to VLC, I use it since 10 years without problem. (started my software  in 2009 with Delphi7, upgrade to Delphi 2010 and in 2019, upgrade to Delphi XE10. As you, I have always one IP interface active on my PC, so I just discovered 2 days ago that my software doesn't continue to send to VLC if I have no IP interface. After search I found this strange result : the difference if I compile using Delphi2010 or if I compile using DelphiXE10

Anyway, nothing to do with UDP,  I can only say that, on the same PC (Win10_64) without LAN interface active, GStack.LocalAddresses.Count gives 1 compiled with Delphi 2010 and says 0 compiled with DelphiXE10
It the reason why I suppose I have miss something in the Delphi XE10 setup.

Thanks also for the idea about Microsoft Network Loopback adapter, I will try if it can be temporary a solution, but , if I can, I don't want to ask to users (more than 2500 people now are using my free software) to add or install something else in case they have no LAN interface.
Reply
#4
"Delphi 2010 and Delphi XE10, only the software compiled with Delphi 2010 can find 127.0.0.1"

This is baffling to me. They both use the same Windows stack. I think you should test this deeper.
Reply
#5
(11-15-2019, 06:45 PM)kudzu Wrote: This is baffling to me. They both use the same Windows stack. I think you should test this deeper.

They may use the same socket stack (WinSock), but not the same Windows APIs to discover the local IPs.

Indy originally used gethostbyname(gethostname()) to enumerate local IPs, which is a bad way to go! It doesn't always work as expected. Later, Indy switched to getaddrinfo(gethostname()) when getaddrinfo() became available, which is still not the right way to go, but at least it has somewhat more predictable results for a local host name. So, it is possible that such APIs explicitly report 127.0.0.1 as an available IP for a local host name even if no other networks are available.

However, modern versions of Indy now use GetAdaptersInfo()/GetAdaptersAddresses() instead, which is Microsoft's official way to enumerate local network adapters and read their local IPs. If there is no active WiFi or Ethernet network available, then there is simply no local IP for the APIs to report. You could easily detect this condition and fallback to 127.0.0.1 manually.

Also, note that the TIdStack.LocalAddress(es) properties are deprecated. Use the TIdStack.GetLocalAddressList() method instead.

Code:
LList := TIdStackLocalAddressList.Create;
try
  GStack.GetLocalAddressList(LList);
  if List.Count > 0 then
  begin
    // use reported IP(s) as needed...
  end else
  begin
    // use 127.0.0.1/::1 as needed...
  end;
finally
  LList.Free;
end;

Reply
#6
I assumed he was using the same Indy version. Does Indy use a different API based on different compiler versions?
Reply
#7
(11-18-2019, 03:25 PM)kudzu Wrote: I assumed he was using the same Indy version.

Delphi 2010 and Delphi 10 (there is no XE10) ship with different versions of Indy.

(11-18-2019, 03:25 PM)kudzu Wrote: Does Indy use a different API based on different compiler versions?

Not the same version of Indy on different compilers, no. But different versions of Indy do use different APIs.

Reply
#8
Hello Remy and Kudzu,

Thanks for your commentary and explanation.
yes it is using Delphi 10 (not Delphi XE10) that I encounter this problem.

As I said in my first post, I also tried the TIdStack.GetLocalAddressList() method.
but no more find 127.0.0.1.

So, yes the only solution is to force manually this IP when I find no available local IP.

We have now to remember that there is this difference between the 2  Delphi compiler versions that use different version of Indy.
Reply
#9
Its not the compiler versions that created the difference, but different versions of Indy.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)