[Q] Linux and localAddress

Norbert Hartl norbert at hartl.name
Wed Oct 31 08:00:31 UTC 2007


On Mon, 2007-10-29 at 17:21 -0300, Edgar J. De Cleene wrote:
> 
> 
> El 10/29/07 4:38 PM, "Hans-Martin Mosner" <hmm at heeg.de> escribió:
> 
> > When you execute
> > "(Socket newTCP connectToHostNamed: 'squeak.org' port: 80) localAddress"
> > you get the address of the interface which can be used to connect to
> > squeak.org.
> > So if your machine is connected to two local networks 192.168.1.x and
> > 192.168.2.x you get back the address of the interface that is connected
> > to the internet (via some router/NAT gateway or whatever).
> > Of course, you should substitute some other address for squeak.org if
> > your network is not connected to the internet.
> > And if you're not a messie, you should clean up after yourself by
> > closing the open socket :-)
> > 
> > Cheers,
> > Hans-Martin
> 
> Thanks, is just what I discover , but better, as I don't need others
> machines on my lan, only trusted web connected machine.

You don't need a web connected machine. The trick Hans-Martin told you
depends on the choice of the outgoing interface which you can request.
The interface is chosen based on the configuration of your linux box.
If you open a connection to any host your linux box tries to figure out
if it knows anything about the host. If it is an unknown machine it
sends all the requests to this host simply to the default gateway. You
can see this by issuing /sbin/route -n on your linux box. The entry
which has 0.0.0.0 is the one I'm speaking of. 
So all you need is to open a connection to this IP (not the 0.0.0.0 
the other one :) ) and you can then request the interface address. This
may be a less error prone than chosing an arbitrary internet host. It
assumes that usually there is a connection to any other net (which
involves a gateway).

my 2 zent

Norbert





More information about the Squeak-dev mailing list