[Vm-dev] unix nameToAddr() function appears to not work on Raspbian?

David T. Lewis lewis at mail.msen.com
Sat Sep 19 14:14:43 UTC 2015


On Sat, Sep 19, 2015 at 08:46:47AM +0200, Hans-Martin Mosner wrote:
> 
> Am 18.09.2015 um 19:50 schrieb tim Rowledge:
> > ...So I?m puzzled since surely asking for an IP address for the machine is a common thing?
> Actually, as David already stated, asking for *the* IP address for a machine is asking for trouble.
> The IP address returned (127.0.1.1) is one of the several IP addresses the machine has (via its several network
> interfaces), so it's perfectly correct, just not usable for your purpose.

To illustrate, try this:

  NetNameResolver addressesForName: 'google.com'

>From where I sit, it looks like this:

  ==>  an OrderedCollection(74.125.225.6(ord08s12-in-f6.1e100.net),0(0)-inet4-stream-tcp 74.125.225.9(ord08s12-in-f9.1e100.net),0(0)-inet4-stream-tcp 74.125.225.5(ord08s12-in-f5.1e100.net),0(0)-inet4-stream-tcp 74.125.225.7(ord08s12-in-f7.1e100.net),0(0)-inet4-stream-tcp 74.125.225.8(ord08s12-in-f8.1e100.net),0(0)-inet4-stream-tcp 74.125.225.14(ord08s12-in-f14.1e100.net),0(0)-inet4-stream-tcp 74.125.225.3(ord08s12-in-f3.1e100.net),0(0)-inet4-stream-tcp 74.125.225.0(ord08s12-in-f0.1e100.net),0(0)-inet4-stream-tcp 74.125.225.4(ord08s12-in-f4.1e100.net),0(0)-inet4-stream-tcp 74.125.225.1(ord08s12-in-f1.1e100.net),0(0)-inet4-stream-tcp 74.125.225.2(ord08s12-in-f2.1e100.net),0(0)-inet4-stream-tcp 2607:f8b0:4009:804::1005(ord08s10-in-x05.1e100.net),0(0)-inet6-stream-tcp)

The #addressesForName: method is used to look up names such as 'localhost' or
your local host name. Results will vary depending on network configuration,
contents of /etc/hosts, and so forth.

> A somewhat more usable function would enumerate all IP addresses of all interfaces and return one that is designated as
> public. However, in many situations a machine might be behind a NAT gateway and only has one or several private IP
> addresses. Determining which of these is the one that you want to use may be very situation-specific.
> So the best thing would be to drop primitiveResolverLocalAddress() altogether, as it is meaningless. Instead enumerate
> all interfaces with all addresses and allow the image to determine with suitable selection algorithms which one to use.
> 

Agreed. I am not sure how to do that though. 

Dave

> Cheers,
> Hans-Martin




More information about the Vm-dev mailing list