[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Bonjour and Socket::getaddrinfo

obrien.andrew@gmail.com

9/27/2006 7:02:00 PM

I was having a problem with DRb coming from Socket::getaddrinfo not
finding an address for the name returned by Socket::gethostname. I'm
running Mac OS 10.4 and Ruby 1.8. Replicating line 837 in drb.rb in
irb gave me this:

irb(main):001:0> require 'socket'
=> true
irb(main):002:0> host = Socket::gethostname
=> "monkeydrome"
irb(main):003:0> Socket::getaddrinfo(host, nil,Socket::AF_UNSPEC,
irb(main):004:1* Socket::SOCK_STREAM,

irb(main):005:1* 0,
irb(main):006:1* Socket::AI_PASSIVE)
SocketError: getaddrinfo: No address associated with nodename
from (irb):3:in `getaddrinfo'
from (irb):3
from :0

And if I add my Bonjour share name to /etc/hosts (as "127.0.0.1
monkeydrome"), I get the correct response ([["AF_INET", 0, "localhost",
"127.0.0.1", 2, 1, 6]]). Is there a way to get the correct address
information without changing /etc/hosts?

Thanks,
Andrew O'Brien

13 Answers

Paul Lutus

9/27/2006 7:08:00 PM

0

obrien.andrew@gmail.com wrote:

> I was having a problem with DRb coming from Socket::getaddrinfo not
> finding an address for the name returned by Socket::gethostname. I'm
> running Mac OS 10.4 and Ruby 1.8. Replicating line 837 in drb.rb in
> irb gave me this:
>
> irb(main):001:0> require 'socket'
> => true
> irb(main):002:0> host = Socket::gethostname
> => "monkeydrome"
> irb(main):003:0> Socket::getaddrinfo(host, nil,Socket::AF_UNSPEC,
> irb(main):004:1* Socket::SOCK_STREAM,
>
> irb(main):005:1* 0,
> irb(main):006:1* Socket::AI_PASSIVE)
> SocketError: getaddrinfo: No address associated with nodename
> from (irb):3:in `getaddrinfo'
> from (irb):3
> from :0
>
> And if I add my Bonjour share name to /etc/hosts (as "127.0.0.1
> monkeydrome"), I get the correct response ([["AF_INET", 0, "localhost",
> "127.0.0.1", 2, 1, 6]]). Is there a way to get the correct address
> information without changing /etc/hosts?

If there is no IP associated with a particular network node, then no, you
can't. The relation between "localhost" and "127.0.0.1" is normally a
relationship created by an entry in /etc/hosts, nowhere else.

--
Paul Lutus
http://www.ara...

Gary Wright

9/27/2006 7:32:00 PM

0


On Sep 27, 2006, at 3:05 PM, obrien.andrew@gmail.com wrote:

> I was having a problem with DRb coming from Socket::getaddrinfo not
> finding an address for the name returned by Socket::gethostname. I'm
> running Mac OS 10.4 and Ruby 1.8. Replicating line 837 in drb.rb in
> irb gave me this:

Strange. This worked just fine for me (Mac OS X 10.4.7, Ruby 1.8.5).

Here is what I get calling getaddrinfo without the extra params:

irb(main):008:0* info = Socket::getaddrinfo(host, nil)
=> [["AF_INET6", 0, "radar.local", "fe80::203:93ff:fe96:4cb4%en0",
30, 2, 17], ["AF_INET6", 0, "radar.local", "fe80::203:93ff:fe96:4cb4%
en0", 30, 1, 6], ["AF_INET", 0, "10.0.1.2", "10.0.1.2", 2, 2, 17],
["AF_INET", 0, "10.0.1.2", "10.0.1.2", 2, 1, 6]]
irb(main):009:0> info = Socket::getaddrinfo('localhost', nil)
=> [["AF_INET6", 0, "localhost", "::1", 30, 2, 17], ["AF_INET6", 0,
"localhost", "::1", 30, 1, 6], ["AF_INET", 0, "localhost",
"127.0.0.1", 2, 2, 17], ["AF_INET", 0, "localhost", "127.0.0.1", 2,
1, 6]]

Gary Wright




obrien.andrew@gmail.com

9/27/2006 7:45:00 PM

0

Thanks for the quick reply, Paul.

I'm not sure I follow: my /etc/hosts had "127.0.0.1" and "localhost"
already specified. I had to add a line for "127.0.0.1" and
"monkeydrome", which is the name I had in the Sharing Preference Pane
(and what Socket::gethostname returns).

My confusion was that I had given the computer a name and I would have
thought that that name would resolve to something, unless I'm
misunderstanding how OS X changes the name (which is more than likely
-- that's why I'm asking :)).

Thanks,
Andrew O'Brien

obrien.andrew@gmail.com

9/27/2006 7:56:00 PM

0

Hi Gary,

What was the value of your "host" variable in that line? "radar" or
"radar.local"?

I can get mine to work if I do Socket::getaddrinfo("monkeydrome.local",
nil), but not with just "monkeydrome" (which is how Socket::gethostname
returns it).

gwtmp01@mac.com wrote:
> On Sep 27, 2006, at 3:05 PM, obrien.andrew@gmail.com wrote:
>
> > I was having a problem with DRb coming from Socket::getaddrinfo not
> > finding an address for the name returned by Socket::gethostname. I'm
> > running Mac OS 10.4 and Ruby 1.8. Replicating line 837 in drb.rb in
> > irb gave me this:
>
> Strange. This worked just fine for me (Mac OS X 10.4.7, Ruby 1.8.5).
>
> Here is what I get calling getaddrinfo without the extra params:
>
> irb(main):008:0* info = Socket::getaddrinfo(host, nil)
> => [["AF_INET6", 0, "radar.local", "fe80::203:93ff:fe96:4cb4%en0",
> 30, 2, 17], ["AF_INET6", 0, "radar.local", "fe80::203:93ff:fe96:4cb4%
> en0", 30, 1, 6], ["AF_INET", 0, "10.0.1.2", "10.0.1.2", 2, 2, 17],
> ["AF_INET", 0, "10.0.1.2", "10.0.1.2", 2, 1, 6]]
> irb(main):009:0> info = Socket::getaddrinfo('localhost', nil)
> => [["AF_INET6", 0, "localhost", "::1", 30, 2, 17], ["AF_INET6", 0,
> "localhost", "::1", 30, 1, 6], ["AF_INET", 0, "localhost",
> "127.0.0.1", 2, 2, 17], ["AF_INET", 0, "localhost", "127.0.0.1", 2,
> 1, 6]]
>
> Gary Wright

Gary Wright

9/27/2006 8:22:00 PM

0


On Sep 27, 2006, at 4:00 PM, obrien.andrew@gmail.com wrote:

> Hi Gary,
>
> What was the value of your "host" variable in that line? "radar" or
> "radar.local"?

It was 'radar.local'. When I run hostname I get 'radar.local' also.
I'm assuming that you are just getting 'monkeydrome'? That doesn't
seem right to me. I think it should be returning 'monkeydrome.local'.
Are you manually setting your hostname somehow and omitting the '.local'
domain?

In the System Preferences/Sharing, my computer name is listed as just
'radar'.

Gary Wright




Paul Lutus

9/27/2006 8:34:00 PM

0

obrien.andrew@gmail.com wrote:

> Thanks for the quick reply, Paul.
>
> I'm not sure I follow: my /etc/hosts had "127.0.0.1" and "localhost"
> already specified. I had to add a line for "127.0.0.1" and
> "monkeydrome", which is the name I had in the Sharing Preference Pane
> (and what Socket::gethostname returns).

I don't recommend this. In many cases, assigning 127.0.0.1 to the system
hostname as well as localhost will cause complete confusion in your local
network.

In any case, if you put a reasonable entry in /etc/hosts, like this:

192.168.0.1 monkeydrome.com monkeydrome

You should get the expected outcome.

>
> My confusion was that I had given the computer a name and I would have
> thought that that name would resolve to something,

It cannot resolve to an IP unless an IP has been assigned, either by DHCP,
by way of /etc/hosts, or some third approach. Having a defined host name
won't produce an address resolution if there is no assigned address.

I want to emphasize that "localhost" is the name of the loopback
pseudo-adaptor, it normally has the address 127.0.0.1, and you don't want
to assign this same address to the system. If you do, the system won't be
visible to your network.

A minimal /etc/hosts might look like this:

127.0.0.1 localhost.localdomain localhost
192.168.0.1 monkeydrome.com monkeydrome

There may be some differences on OS X, the above is typical in Linux. Also,
obviously, the address you assign to the local system might not be such a
generic choice as 192.168.0.1, although that is a reasonable choice if you
don't have a special reason to use another.

--
Paul Lutus
http://www.ara...

obrien.andrew@gmail.com

9/27/2006 8:42:00 PM

0

gwtmp01@mac.com wrote:
> I'm assuming that you are just getting 'monkeydrome'?

Yep.

> Are you manually setting your hostname somehow and omitting the '.local'
> domain?

Hmm, don't think so... but it is possible that I messed something up
when I first started learning. I'm guessing that's the case since I
haven't seen too many similar complaints on the net. I must have just
screwed up my environment somehow along the way. Good to know it's not
a problem with the library or the OS.

If I do "hostname -s monkeydrome.local", everything works, so I'd say
that pretty much solves that.

> In the System Preferences/Sharing, my computer name is listed as just
> 'radar'.

Yeah same here. Must just be a problem on my end.

Thanks for the help,
Andrew O'Brien

Paul Lutus

9/27/2006 8:52:00 PM

0

obrien.andrew@gmail.com wrote:

> If I do "hostname -s monkeydrome.local", everything works, so I'd say
> that pretty much solves that.

Yes, as long as you realize this change won't survive a reboot. Typically,
the real hostname, the one that persists, is in /etc//hostname, and is read
during boot-up. This information is based on a typical *nix environment, it
may not fully apply to OS X.

--
Paul Lutus
http://www.ara...

Gary Wright

9/27/2006 9:00:00 PM

0


On Sep 27, 2006, at 4:40 PM, Paul Lutus wrote:
> A minimal /etc/hosts might look like this:
>
> 127.0.0.1 localhost.localdomain localhost
> 192.168.0.1 monkeydrome.com monkeydrome

/etc/hosts on my Mac looks like:

127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost

This is the 'out of the box' configuration. I didn't have to
add anything. Also my bonjour host name 'radar.local' is resolved
automatically with no need to play with /etc/hosts.


Gary Wright




Gary Wright

9/27/2006 9:02:00 PM

0


On Sep 27, 2006, at 4:45 PM, obrien.andrew@gmail.com wrote:
> If I do "hostname -s monkeydrome.local", everything works, so I'd say
> that pretty much solves that.

If you feel so inclined, I'd take a look at any startup scripts you may
have added or modified or perhaps any shell startup scripts
(.profile, and
so on) that might get executed as root and include any calls to
hostname.


Gary Wright