localHostAddress

John M McIntosh johnmci at smalltalkconsulting.com
Sat Oct 6 23:03:17 UTC 2007


Let's see. First on os-x we just use the unix socket code so looking  
at the primitive we see

EXPORT(sqInt) primitiveResolverLocalAddress(void) {
	sqInt addr;
	sqInt _return_value;

	addr = sqResolverLocalAddress();

which is

sqInt sqResolverLocalAddress(void)		{ return nameToAddr 
(localHostName); }

which is

/* answer the IP address for the given hostname */

static int nameToAddr(char *hostName)
{
   struct hostent *he;

   lastError= 0;			/* ditto */
   if ((he= gethostbyname(hostName)))
     return ntohl(*(long *)(he->h_addr_list[0]));
   lastError= h_errno;		/* and one more ditto */
   return 0;
}

      The gethostbyname(), gethostbyname2() and gethostbyaddr()  
functions each
      return a pointer to an object with the following structure  
describing an
      internet host referenced by name or by address, respectively.   
This
      structure contains either the information obtained from the  
name server,
      named(8), or broken-out fields from a line in /etc/hosts.  If  
the local
      name server is not running these routines do a lookup in /etc/ 
hosts.

      struct  hostent {
              char    *h_name;        /* official name of host */
              char    **h_aliases;    /* alias list */
              int     h_addrtype;     /* host address type */
              int     h_length;       /* length of address */
              char    **h_addr_list;  /* list of addresses from name  
server */
      };


Now on this machine there are multiple network interfaces

en0 is ethernetport
en1 is 802.11n (wireless, active)
en2 is Parallels virtual interface for Host-Guest
en3 is Parallels virtual interface for NAT

I'll note the machine is otter.local.
If I ping say otter.local it says

[otter:~] johnmci% ping Otter.local
PING otter.local (10.37.129.2): 56 data bytes
64 bytes from 10.37.129.2: icmp_seq=0 ttl=64 time=0.034 ms
64 bytes from 10.37.129.2: icmp_seq=1 ttl=64 time=0.070 ms
64 bytes from 10.37.129.2: icmp_seq=2 ttl=64 time=0.064 ms
64 bytes from 10.37.129.2: icmp_seq=3 ttl=64 time=0.090 ms

another try gave me

[otter:~] johnmci% ping otter.local
PING otter.local (192.168.1.130): 56 data bytes
64 bytes from 192.168.1.130: icmp_seq=0 ttl=64 time=0.024 ms
64 bytes from 192.168.1.130: icmp_seq=1 ttl=64 time=0.066 ms
64 bytes from 192.168.1.130: icmp_seq=2 ttl=64 time=0.080 ms
64 bytes from 192.168.1.130: icmp_seq=3 ttl=64 time=0.086 ms

In checking the results from gethostbyname I get
h_name -> otter.local
h_aliases -> address -> 0x00000000
h_addresstype -> 2
h_length -> 4
h_addr_list -> address -> ox0a258102


So the gethostbyname is returning the address of the Parallels  
virtual interface for Hosts-Guest
So obviously the unix call might not return what you think it should  
if there are multiple interfaces active for your machine.
I'l do a ifconfig -a and see what's lurking

en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
         ether 00:17:f2:d9:57:35
         media: autoselect status: inactive
         supported media: autoselect 10baseT/UTP <half-duplex>  
10baseT/UTP <full-duplex> 10baseT/UTP <full-duplex,hw-loopback>  
10baseT/UTP <full-duplex,flow-control> 100baseTX <half-duplex>  
100baseTX <full-duplex> 100baseTX <full-duplex,hw-loopback> 100baseTX  
<full-duplex,flow-control> 1000baseT <full-duplex> 1000baseT <full- 
duplex,hw-loopback> 1000baseT <full-duplex,flow-control> none
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
         inet6 fe80::21b:63ff:fe02:d2db%en1 prefixlen 64 scopeid 0x5
         inet 192.168.1.130 netmask 0xffffff00 broadcast 192.168.1.255
         ether 00:1b:63:02:d2:db
         media: autoselect status: active
         supported media: autoselect
en2: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST>  
mtu 1500
         inet6 fe80::201:23ff:fe45:6789%en2 prefixlen 64 scopeid 0x8
         inet 10.37.129.2 netmask 0xffffff00 broadcast 10.37.129.255
         ether 00:01:23:45:67:89
         media: autoselect status: active
         supported media: autoselect
en3: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST>  
mtu 1500
         inet6 fe80::210:32ff:fe54:7698%en3 prefixlen 64 scopeid 0x9
         inet 10.211.55.2 netmask 0xffffff00 broadcast 10.211.55.255
         ether 00:10:32:54:76:98
         media: autoselect status: active
         supported media: autoselect



On Oct 6, 2007, at 3:18 PM, Robert Arning wrote:

>
> I haven't tried this in a while (previous computer), but I'm not  
> able to get
> the address of my computer.
>
> NetNameResolver localHostAddress ==> a ByteArray(0 0 0 0)
>
> All the other NetNameResolver functions seem to be working fine,  
> including
> giving it my address and having it lookup the name.
>
> This is MacOS 10.4 and I have tried in a Croquet 1.0 image and a  
> much older
> image as well.
>
> I have a feeling this requires some sort of UNIX incantation, but  
> I'm not
> sure what. Any ideas?
>
> Cheers,
> Bob
> -- 
> View this message in context: http://www.nabble.com/ 
> localHostAddress-tf4581383.html#a13078111
> Sent from the Squeak - Dev mailing list archive at Nabble.com.
>
>

--
======================================================================== 
===
John M. McIntosh <johnmci at smalltalkconsulting.com>
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
======================================================================== 
===





More information about the Squeak-dev mailing list