[Vm-dev] [commit][3485] update resolver local address discovery; it seem gethostbyaddr has been compromised by OS changes recently.

David T. Lewis lewis at mail.msen.com
Sat Nov 7 19:28:06 UTC 2015


On Thu, Nov 05, 2015 at 12:57:18PM -0800, tim Rowledge wrote:
> 
> 
> > On 05-11-2015, at 12:53 PM, commits at squeakvm.org wrote:
> > 
> > 
> > Revision: 3485
> > Author:   rowledge
> > Date:     2015-11-05 12:53:44 -0800 (Thu, 05 Nov 2015)
> > Log Message:
> > -----------
> > update resolver local address discovery; it seem gethostbyaddr has been compromised by OS changes recently. Change to using ifgetaddrs and scanning for eth0 or wlan0 addresses, which looks like a good change on Raspbian at least.
> 
> I???m very much a guess-and-hope guy when it comes to sockets, so please offer any improvements you can think of.
> 

I tried this change on my Ubuntu laptop, and it provides a useful result.
This is with wireless wlan0 active, and eth0 not plugged in.

  NetNameResolver useOldNetwork: true.
  NetNameResolver localHostAddress. "==> #[172 16 0 6]"

However, we would still need to sort out an implementation that works with
the IPV6 support enabled (maybe easy to do, I'm not sure). That is because
#primLocalAddress answers a ByteArray representation of an IPV4 address,
whereas with new networking enabled, we want an instance of SocketAddress
instead. This is done with 'NetNameResolver addressForName: self localHostName',
which results in 127.0.1.1 on my laptop, and that of course is the original
problem that we were trying solve.

  NetNameResolver useOldNetwork: false.
  NetNameResolver localHostAddress. "==> 127.0.1.1(lewis-Gazelle-Pro),0(0)"

The UDP connection lookup approach (Bert's suggestion, also requires a
plugin patch) does give a useful result in either case:

  NetNameResolver useOldNetwork: true.
  s := Socket newUDP setPeer: (NetNameResolver addressForName: '8.8.8.8') port: 0.l.
  local := s localAddress.
  s close.
  local "==> #[172 16 0 6]"

  NetNameResolver useOldNetwork: false.
  s := Socket newUDP setPeer: (NetNameResolver addressForName: '8.8.8.8') port: 0.l.
  local := s localAddress.
  s close.
  local "==> 172.16.0.6(172.16.0.6),0(0)"

Dave
 


More information about the Vm-dev mailing list