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

tim Rowledge tim at rowledge.org
Mon Sep 21 18:17:02 UTC 2015


On 21-09-2015, at 10:17 AM, tim Rowledge <tim at rowledge.org> wrote:
> On 21-09-2015, at 5:27 AM, Bert Freudenberg <bert at freudenbergs.de> wrote:
>> python -c "import socket; s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.connect(('8.8.8.8', 80)); print(s.getsockname()[0]); s.close()"
>> 
>> I tried that on a Linux and OS X, works on both. We should be able to do that in Squeak using a UDP socket, no?

Doesn’t seem to want to work in my pi image; the simple version (bearing in mind an almost total lack of knowledge about sockets)

| foo bar|
foo := Socket newUDP.
foo connectTo: #[8 8 8 8] port: 80.
bar := foo localAddress.
foo close.
bar

fails to do the connect since 
a) UDP sockets are created with the status set to connected
b) the #connectNoBlockingTo:port: method carefully checks for the status and fails when it is not ‘Unconnected’.

Trying a #setPeer:port: instead - which calls the primSocket:connectTo:port: directly and skips the status test - doesn’t leave me with anything interesting from #localAddress.

I even tried a quick ‘sendUDPData:’hello’ toHost: #[8 8 8 8] port: 80’ (which appeared to work) and still localAddress is 0.0.0.0 ‘self peerName’ is google-public-dns-a.google.com so it looks like I made some sort of connection.

Substituting a newTCP for the newUDP actually returned a useful IP number after a long delay and a notifier that it couldn’t connect. So as a desperate last attempt I tried 
| foo bar|
foo := Socket newTCP.
foo setPeer: #[8 8 8 8] port: 80.
bar := foo localAddress.
foo close.
bar
- which worked essentially instantly. I even tried it on another Pi to make sure nothing was being locally cached.

I guess I can live with that if it’s the best we can do but
- does it point to a problem with our TCP sockets?
- it can’t work (presumably) if the machine is not on an externally connected network, which is quite plausible in many schools in many countries
- [8 8 8 8] is the sort of magic number nonsense I hate to see. 

Can’t we do better?

tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
Useful random insult:- Couldn't find his way through a maze even if the rats helped him.




More information about the Vm-dev mailing list