Finding Local Ip within Blitzmax on OSX

BlitzMax Forums/BlitzMax Beginners Area/Finding Local Ip within Blitzmax on OSX

cps(Posted 2016) [#1]
I have been using this on a PC : My Computer local IP = DottedIP (HostIp ("", 0))
To get a string of the form xxx.xxx.xxx.xxx for networking however on my Imac (OSX) I get 0.0.0.0
Is there some way of getting the local IP in blitzmax on OSX. I can see the IP listed when I use the mac network utility,
but this changes depending on the computers attached to my network (dynamically assigned no doubt) so storing the value in a txt file won't do.
Please could somebody point me in the right direction. Have fun Cps


Ked(Posted 2016) [#2]
I always enter "localhost" in the HostIP function. It will return "127.0.0.1" obviously. An easy alternative though would be just to give your computers network names. Then, you could just type in:
Local address:String = DottedIP(HostIP("COMPUTERNAME_HERE"))
Your IPs may be dynamic but the computer names are static.


Brucey(Posted 2016) [#3]
BaH.inet can retrieve some useful information:
Interface   : lo0
            : UP, LOOPBACK, RUNNING, MULTICAST
IP Address  : 127.0.0.1
Netmask     : 255.0.0.0
Broadcast   : 127.255.255.255
MAC Address : 00:00:00:00:00:00

Interface   : en0
            : UP, BROADCAST, RUNNING, SIMPLEX, MULTICAST
IP Address  : 192.168.1.124
Netmask     : 255.255.255.0
Broadcast   : 192.168.1.255
MAC Address : xxxxxxxxxxxxxx



cps(Posted 2016) [#4]
Ked, many thanks : I was using CPU names for PC-PC comms but that hasn't worked on PC-MAC comms so now I'm using Local IP's.
I've retried your suggested approach and found that if I use "MyLocalMacName.Local" I get the correct IP on a mac. So now I can simply prompt the user to enter the local cpu name on
the first pass through the program, then store it to derive the correct IP. Just got to check what 'Brucey' supplied to see if I can get at the local cpu name without user input, thanks again.
Brucey, many thanks : I'm going to have to give this Bah.inet a good workout as it seems to provide all info needed.
Many thanks again to both of you. Your input is most appreciated and will find its way into BaseNetV4 (like BaseNetV3 but with added MAC support), and
from there into a range of digital renditions of (popular ??) 2D board games... Have fun Cps


xlsior(Posted 2016) [#5]
On windows the local CPU name is an environment variable -- Don't know if OSX has something similar?

Print GetEnv_("COMPUTERNAME"



cps(Posted 2016) [#6]
xlsior, many thanks however OSX returns a null string. I'll keep looking for something similar though for OSX. Have fun Cps


cps(Posted 2016) [#7]
Here is a solution provided by simonarmstrong from a thread about detecting operating systems. (if using MaxGui)
MacName$=ComputerName$() and MacUser$=UserName$()' undocumented functions
Hence
LocalMacName$=replace(ComputerName$," ","-")+".local" and DottedIP$=DottedIP(HostIp(LocalMacName$))
Which if universal (applies to all Mac OSX) then problem solved.
Again many thanks to all contributers, have fun Cps