Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
FAQ: How do I find out the Loop back address(es) of my machine?
Last updated at 4:51 pm UTC on 16 January 2006
Ned Konz:

On my Linux system, 3.3a-4771:

NetNameResolver localHostAddress -> a ByteArray(0 0 0 0)
Socket initializeNetwork "is necessary if the above is returned"
NetNameResolver localHostAddress -> a ByteArray(192 168 1 2)

Same on a 3.2g system.

Gerald Zincke:

On my Windows 2000 Professional system:

The above only displays the first IP address (which is bound to my LAN adapter; see also discussion below). So I found a more general - although not elegant - way to get all IP addresses. This should - with slight modifications - work not only in Windows.

Win32Shell new shellOpen: 'c:\getips.cmd'.
str := FileStream fileNamed: 'c:\getips.txt'.
str upToAll:'. : '.
str upToAll:'. : '.
myIP := (str upTo:(Character cr)) .

It works as follows:

The command procedure (shell script) getIPS.cmd is a one-liner and looks like:

ipconfig | find "IP Ad" > getips.txt

This calls the command "ipconfig" which displays info about the IP configuration of the system. Its output is piped into the "find" command to reduce it to those lines, I am interested in. The result is the "getIPs.txt" file, which looks like:

IP Address. . . . . . . . . . . . : 192.168.1.2
IP Address. . . . . . . . . . . . : 123.45.67.98

The squeak code calls the procedure and then does some silly parsing in the txt-file.

From: nop@nop.com
Subject: RE: SOAP for multiple images on the same host
Date: Fri, 1 Mar 2002 13:53:06 -0600 (CST)

On Fri, 1 Mar 2002, Stephen Pair wrote:

> Anthony Hannan wrote:
> > You use a different port number for every socket you create.
> > A machine can have more than one socket connections.
> > However, a machine only has one ip address.
>
> This is not strictly accurate (as I'm sure Anthony is aware)...it's
> usually the case that a machine has only one ip address, but many
> machines (and most server machines) have multiple ip addresses.

This is a pet peeve of mine too. Here's the bumper-sticker version:

MACHINES DON'T HAVE IP ADDRESSES
NETWORK INTERFACES HAVE IP ADDRESSES

It is an error to ask "what is this machine's IP address", whether verbally or in code. For desktop machines, humans can usually accept this as a natural language shortcut for "what is the IP address of the sole external network interface", but these days, code will usually get bitten by that kind of shorthand.

Even in that desktop machine case, you run into problems—there are two network interfaces, and hence two IP addresses:

> > To find the ip
> > address of your machine do "NetNameResolver localHostAddress"
> > you may have to do "Socket initializeNetwork" first.
>
> In fact, "NetNameResolver localHostAddress" always reports the loopback address of 127.0.0.1 (on all the OSes that I've used Squeak on).

If you want to stick to the "what is this machine's IP address" question, then the right answer for desktop machines is: "this machine has TWO IP addresses: 129.83.9.112 and 127.0.0.1."

However, when my laptop is not connected to an external network, the only interface available is the loopback network, and the connection to that network has the IP address 127.0.0.1, which may not be the answer you want—because it's the wrong question.

The right question is more like "what address can a particular machine use to contact me?" In many cases these days, the answer may be "you can't". Obviously when my laptop is disconnected from external networks, "none" is the answer for this question about any remote host. Network Address Translation and firewalls are another good source of "none"....

If I have a host that has connections to two different external networks, the answer depends on what network the remote host is on. For machines on the inside of a firewall, a boundary machine may be reachable as "10.0.0.1", but outside hosts reach it as "129.83.10.1". With the advent of host-based VPNs, many machines are in this category—the interface connecting to my ISP has a different address than the one that the VPN tunnel provides.

Virtual hosts are a slightly different problem. The machine my mail server lives on has a number of different network interfaces; place.org has one address, sadclown.org has another. [] The answer to "what address can a particular machine use to contact me" depends on the role/aspect of the machine you intend to contact.

A related way to get yourself into trouble is to try to use hostnames to answer these kinds of questions. My laptop's primary name for itself is "imipolex", but if I'm away from my desk and using DHCP, telling somebody else to contact me at the hostname imipolex will get them dead air, as the IP address associated with that name refers to the Ethernet adapter on the docking station, not to the 802.11b wireless adapter's DHCP-assigned address.

There is one easy mostly-correct technique to answer the "how to contact" question: derive the answer from a connection that's already open. If I'm running a server and get an incoming call from foo.com (port 1027) to my address sadclown.com (port 80), I can usually tell foo.com to reach me again at sadclown.com's address. Firewalls and most NAT break this, but they're supposed to.

>This is a shortcoming of the squeak socket interface IMO.

It's difficult to write correct programs that function in our modern network environments without a lot of detail that we used to ignore.

As an aside, this is just one way that the assumptions of desktop computing have subtly snuck into a lot of code. Because our laptop computers are just desktop machines with handles, they're the first to get bitten by these network assumptions. Another example is display management. Many applications assume that the display they're running on is a mostly-private conduit to a particular user; the first time you get an instant message from your spouse on a projected, wall sized display in the middle of a presentation, you might be motivated to think about what went wrong where. :-)

Squeak could be a framework to revisit some of these assumptions.

Jay

[] Actually, place.org mostly switched over to HTTP 1.1 Host-header virtual hosting, so these are now the same IP address.