TCPGetMyAddr

Kelly Burgess kellyb at montana.com
Tue Sep 20 09:27:34 UTC 2022


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
> 




More information about the omnisdev-en mailing list