[Vm-dev] Finding ip address for eth0?
John M McIntosh
johnmci at smalltalkconsulting.com
Wed Aug 26 22:18:05 UTC 2009
Sure well
NetNameResolver localHostName
gives me
'Otter-2.local'
then
NetNameResolver addressesForName: 'Otter-2.local'
gives me back a collection with 6 addresses, but you are saying for
your machine you only get back 1 address? Lucky you, but will your
production machine
give back one address, or 23?
I think here the problem is your machine is returning
'localhost.localdomain'
Oddly on os-x asking for NetNameResolver addressForName:
'localhost.localdomain'
gives you a primitive failure.
Also as you saw, my localHostName is 'Otter-2.local' which is the
boujour name http://support.apple.com/kb/TA20999?viewlocale=en_US
Maybe the question is does your computer have a DNS assigned name?
In Pharo Ian's code is below, note how the
SocketAddressInformation>>forHost:... iterates to get all the socket
info.
addressesForName: hostName
"NetNameResolver addressesForName: 'impara.de' "
| adresses |
adresses := SocketAddressInformation
forHost: hostName
service: ''
flags: 0
addressFamily: 0
socketType: SocketAddressInformation socketTypeStream
protocol: SocketAddressInformation protocolTCP.
^adresses
SocketAddressInformation >>forHost: hostName service: servName flags:
flags addressFamily: family socketType: type protocol: protocol
| result addr |
NetNameResolver initializeNetwork.
NetNameResolver primGetAddressInfoHost: hostName service: servName
flags: flags family: family type: type protocol: protocol.
result := OrderedCollection new.
[(addr := NetNameResolver nextSocketAddressInformation) notNil]
whileTrue: [result add: addr].
^result
On 26-Aug-09, at 2:57 PM, Andreas Raab wrote:
> John M McIntosh wrote:
>> NetNameResolver addressesForName: self localHostName
>
> This doesn't work at all for me. In fact it's not even asking the
> right question ;-) Using the 3.10-6 VM with an Etoys-dev image I get
> this:
>
> NetNameResolver localHostName
> => 'localhost.localdomain'
>
> NetNameResolver addressesForName: NetNameResolver localHostName
> => 127.0.0.1(localhost),0(0)-inet4-stream-tcp
>
> I'm not surprised with the result because you are asking DNS to
> resolve localhost.localdomain which is different from asking the
> question of what IP addresses are assigned to the various interfaces
> in your system.
>
> I thought Bert said that there is a way to enumerate the IP
> addresses of the interfaces?
>
> Cheers,
> - Andreas
>
--
=
=
=
========================================================================
John M. McIntosh <johnmci at smalltalkconsulting.com> Twitter:
squeaker68882
Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com
=
=
=
========================================================================
More information about the Vm-dev
mailing list