Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] GStack.LocalAddress returns empty
#2
(11-05-2018, 12:38 AM)capslock Wrote: I'm using Indy 10 + fpc + lazarus to build a cross platform app.

GStack.LocalAddress returns the IP address at Windows, but returns empty at Linux, and GStack.LocalAddresses.Count = 0. The machine has an ip address, checked by ifconfig.

First, the GStack.LocalAddress and GStack.LocalAddresses properties are deprecated, you should be using the GStack.GetLocalAddressList() method instead.

Second, on FPC for Linux, GStack points to an instance of either the TIdStackLibc or TIdStackUnix class (depending on whether KYLIXCOMPAT is defined).  Both classes should implement GetLocalAddressList() using getifaddrs(), but in actuality they only do so when HAS_getifaddrs is defined in IdCompilerDefines.inc, and that is defined only when LINUX64 is defined by the compiler (in addition to MACOS, IOS, and FREEBSD).  Which, I believe is defined by Embarcadero only, not FPC.

When HAS_getifaddrs() is not defined, both TIdStackLibc and TIdStackUnix implement GetLocalAddressList() using gethostname() with gethostbyname() (Libc) or FPC's own ResolveName/6() (Unix) instead. And I guess that is not finding any IP addresses for the local hostname.

So, try altering IdCompilerDefines.inc to define HAS_getifaddrs for LINUX instead of LINUX64.  If that works, I'll check it in.

Reply


Messages In This Thread
RE: GStack.LocalAddress returns empty - by rlebeau - 11-05-2018, 06:25 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)