How to find a machine's IP address

As far as I can see, I should look to see if Inet$LocalAddr exists. If it does, I can use that. If not, I have to find Inet$EtherIPAddr and resolve it, because it might be numeric or a machine name, so I can’t just parse numbers out of it.

And, presumably, if I can’t resolve Inet$EtherIPAddr, it means that the machine isn’t actually on the LAN – something must have failed at startup.

Is the above correct?

Under what conditions is Inet$EtherIPAddr numeric, and when is it a name?

You are right that using an entry in the hosts file allows you tu use the text name which also turns up in Inet$EtherIPAddr
I’m not sure why you would prefer to do that though, and dhcp probably only works with numbers. Does choices get written to
after dhcp has given the machine an address?*Do ifping <Inet$EtherIPAddr> Then gethost <Inet$EtherIPAddr> { > temp }
Dave may be after SWI’s

I really should go through all the combinations of network configuration settings and try them. My BBxM has a static IP address from host name, so Inet$LocalAddr exists (numeric) and Inet$EtherIPAddr exists (the machine’s name, not numeric). Experience supporting JDServer proved that Inet$LocalAddr does not always exist, though the specific case had a numeric Inet$EtherIPAddr. I don’t know if it is ever possible for Inet$LocalAddr to not exist AND Inet$EtherIPAddr to be non-numeric.

I noticed that using *ifping or *gethost makes BASIC jump back to the CLI so you would either have to make the tempfile in the application obey file, or make an obey file with those commands and run that from BASIC.
Complicated star command strings can be tough in BASIC anyway. trying *wimptask almost cuts it, and there is probably a way.
Ifping does give you the advantage of checking inet is actually there at that time, but if someone with a USB network device could pull it out and check the variables for a change it might only mean you check that variable.
gethost will give you the numeric address regardless of which type is the hostname.
The Inet SWI’s appear to me to be one or the other.
You could probably modify the source of !Internet.bin.gethost to get the actual numeric address into a variable, to save opening a temp file.
Could be a handy utility if nothing already does it.

With all of the combinations I have tried * on Raspberry Pi RC15 with USB networking, Inet$LocalAddr should exist with a valid address. If it does not, then the networking is going to fail anyway as the machine has not been set up properly.

Inet$LocalAddr needs thinking about how to parse it. But, other than that, it is very easy to access from Basic

If networking is not set up, you can still obtain the machine’s MAC address (except on Beagleboard, Pandaboard and IGEPv5 which do not have a MAC address, just a locally administered address). Even a model A Pi has a MAC address even though it has no network adapter.

Of course what nobody’s spotted yet is that the reason the question is hard to answer is because the question is nonsense. A machine doesn’t have an IP address, it’s an interface that does. A machine can have more than one (physical) interface, and some drivers allow you to have virtual (software) interfaces, and would hence have more than one IP address too.

You can ask what the IP address of an interface is by opening a datagram socket (SOCK_DGRAM) then using an ioctl to request SIOCGIFADDR and SIOCGIFNETMASK. Both ifconfig and InetSetup’s status dialogue do this (in C), converting to BASIC and calling the appropriate Socket_ SWIs is certainly possible, but left as an exercise for masochists.

Of course what nobody’s spotted yet is that the reason the question is hard to answer is because the question is nonsense. A machine doesn’t have an IP address, it’s an interface that does.

While it’s true that the interface has assigned IP’s1 the question Dave asked was “Under what conditions is Inet$EtherIPAddr numeric, and when is it a name?” to which the answer is Inet$EtherIPAddr numeric but the name can be resolved to the value stored in Inet$EtherIPAddr. However I thought that answer had pretty much been covered by John Williams with the list including his personal values for Inet$EtherIPAddr and Inet$HostName.
Reasons why Inet$Hostname would not resolve to the value in Inet$EtherIPAddr are a different question but possibly leads you into a discussion of how crufty and old the network stack is.

1A NIC could have a configuration with 192.168.112.13 and 224.0.23.63 simultantaneously. Specific combination quoted from a bit of “multicast network fault” which I spent 82 hours investigating and finally established that my first impression of it being a host system fault was actually totally correct.
Pedants might argue that the NIC is the hardware and the interface is a logical entity associated with the hardware in many cases

True – but it isn’t nonsense. Most people will be used to a “device” having an “address”. My router is 192.168.1.1, the Pi is 192.168.1.10 (via 192.168.1.19 (Vonets)). The IPCam iswas 192.168.1.20. My printer is …14. My phone is …12, blah blah blah.

A machine can have more than one (physical) interface,

And what would net$EtherIPAddr be in this case? Or are you talking about “a machine that can do networking correctly” which isn’t RISC OS?

converting to BASIC and calling the appropriate Socket_ SWIs is certainly possible, but left as an exercise for masochists.

Uhhh… yeah… I’m still recovering from the beating-head-on-desk that got me to ip% = !(!(rb%!16)) for dealing with the response from the Resolver.

Calm down, calm down. It was just an example of the joy of dealing with network stuff in BASIC.

In another thread they’re discussing unicorns and Romans, and you and I both know that such things were alive and kicking when the RISC OS network stack was created. In fact, I would hazard a guess that the Resolver of which we speak predates the Dodo. Maybe also the evolutionary development of the Tardigrade? I dunno. There’s not so much cobwebs as trap doors and giant rolling stones…

Yes, it’s a string, but that string represents a hex number as you say, which is why I (rather loosely) said it’s a number.

But I have evidence from another user that Inet$LocalAddr doesn’t always exist, so my question is about how to find the machine’s address (almost all machines we’re dealing with have only one interface and therefore only one address) when Inet$LocalAddr doesn’t exist.