[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 02:48:35 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.
>

Hi Tim,

This seems a reasonable approach, although the man page suggests that
the getifaddrs function may be available only on some BSD Linux systems,
and seems to behave differently between those as well. Harumph.

I had opened a mantis issue based on an earlier suggestion from Bert,
with a patch that allows use of Bert's suggestion of:

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

Unfortunately I messed up the problem description on the mantis entry, so
I just closed it and reopened it here:

  http://bugs.squeak.org/view.php?id=7837

The problem that Bert and Tobias identified was that the connect method
in the plugin failed to actually do the connect() call. This may have been
related to some experiments with UDP networking (per earlier email from Ian),
though it looks to me like just an oversight that needs to be fixed.

If this approach works for you (and I think it will) then I would suggest
using that instead of the getifaddrs approach, because it seems to work well
enough and it avoids some portability issues.

Patch is on the mantis report, but it is small so I'll paste it here:

Index: sqUnixSocket.c
===================================================================
--- sqUnixSocket.c	(revision 3485)
+++ sqUnixSocket.c	(working copy)
@@ -695,9 +695,12 @@
       /* --- UDP --- */
       if (SOCKET(s) >= 0)
 	{
+	  int result;
 	  memcpy((void *)&SOCKETPEER(s), (void *)&saddr, sizeof(saddr));
 	  SOCKETPEERSIZE(s)= sizeof(struct sockaddr_in);
-	  SOCKETSTATE(s)= Connected;
+	  result= connect(SOCKET(s), (struct sockaddr *)&saddr, sizeof(saddr));
+	  if (result == 0)
+	    SOCKETSTATE(s)= Connected;
 	}
     }
   else
@@ -1978,9 +1981,12 @@
     {
       if (SOCKET(s) >= 0)
 	{
+	  int result;
 	  memcpy((void *)&SOCKETPEER(s), socketAddress(addr), addressSize(addr));
 	  SOCKETPEERSIZE(s)= addressSize(addr);
-	  SOCKETSTATE(s)= Connected;
+	  result= connect(SOCKET(s), socketAddress(addr), addressSize(addr));
+	  if (result == 0)
+	    SOCKETSTATE(s)= Connected;
 	}
     }
   else					/* --- TCP --- */






More information about the Vm-dev mailing list