TCPGetMyAddr

Paul Mulroney pmulroney at logicaldevelopments.com.au
Wed Sep 21 00:21:46 UTC 2022


Hi Kelly,

I've tested that on my MacBookPro, Catalina, Studio 10.2 build 31315 - I get a 192.168... address

I use Parallels so I ran the same command in a windows 10 VM, Studio 10.2 build 31315, ) get a 192.168... address

I tried an iMac running Big Sur, Studio 10.2 build 31315 with a new empty library, one code class method with one command I get a 192.168... address

I wonder what the difference is?

I guess we could call TCPGetMyAddr and if it returns 127.0.0.1 or 0, then we could try to open a socket to somewhere known and try again.  On the mac I guess we could also $runapplescript() to get the ip address using something like "ipconfig getifaddr en0"

Regards,
Paul.



> On 20 Sep 2022, at 5:27 pm, Kelly Burgess <kellyb at montana.com> wrote:
> 
> I wrote:
>> TCPGetMyAddr() returns 127.0.0.1 here on Catalina with Studio 10.2 31315
> 
> By contrast, on several Mac VMs I tried, TCPGetMyAddr() returned 0, not 127.0.0.1 (El Capitan, High Sierra, Monterey), and on one VM (Big Sur) it returned -11001, the error code for Lookup error: Host not found.
> 
> So like the docs additional notes say, "When passing no socket to TCPGetMyAddr, the code uses the gethostname operating system API to obtain the name of the system, and then uses the getaddrinfo operating system API to obtain a list of addresses for the host."
> 
> And as I found out, gethostname and getaddrinfo aren't behaving the same way in the VMs as they do on the Catalina OS that is hosting the VMs (with VMWare Fusion).  Using a socket parameter is the only solution in those environments.
> 
> Kelly
> 
> 
>> On Sep 19, 2022, at 2:56 PM, Kelly Burgess <kellyb at montana.com> wrote:
>> 
>> Hi Das,
>> 
>>> Latest Monterey on Mac with 10.2 30204
>>> On that platform it returns 127.0.0.1 instead of like 192.168…
>>> It works on Windows and on Catalina Mac
>> 
>> TCPGetMyAddr() returns 127.0.0.1 here on Catalina with Studio 10.2 31315
>> 
>> But if I connect a socket to something and then check using that socket, I get 10.0.0.21 - my LAN address.
>> 
>>  TCPConnect ('www.kellyb.com',80,kFalse,kFalse) Returns socket
>>  TCPGetMyAddr (socket) Returns ipAddress
>>  TCPClose (socket,0)
>> 
>> The docs say:
>> 	• It is not a mandatory requirement that a WinSock API implementation can return the local IP address, without a socket for an open connection. In this case it is likely that TCPGetMyAddr will return 0.0.0.0.
>> 
>> 	• If the local machine has more than one IP address, passing a socket eliminates ambiguity, and returns the local IP address used for the open connection.
>> 
>> There are additional notes re IP v4 vs v6 and Operating System and config variations:
>> 
>>  https://omnis.net/developers/resources/onlinedocs/CommandRef/Commands_A-Z/tcpgetmyaddr.html#tcpgetmyaddr
>> 
>> Kelly
>> 
> 
> 
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com 




  <https://www.logicaldevelopments.com.au/>	Paul W Mulroney
Logical Developments
Customised Software Solutions
Ph: 08 9458 3889
 	We Don't Do Simple Pty Ltd
trading as
Logical Developments
ACN 161 009 374
 	  <https://www.facebook.com/logicaldevelopmentswa/>   <https://twitter.com/WeDontDoSimple>   <https://www.linkedin.com/company/logicaldevelopments/>   <https://www.youtube.com/channel/UCPldVVgWR05WX3cVrR5WUQw>


More information about the omnisdev-en mailing list