Bonjour and Socket::getaddrinfo

O

obrien.andrew

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
 
G

gwtmp01

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
 
O

obrien.andrew

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
 
O

obrien.andrew

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).

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
 
G

gwtmp01

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
 
O

obrien.andrew

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
 
G

gwtmp01

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
 
G

gwtmp01

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
 
O

obrien.andrew

Paul: I removed the line from /etc/hosts like you recommended --
something in my head was telling me that that wasn't really a good idea
anyway.

Also, I have no /etc/hostname file. I think OS X has a different way
of assigning hostnames.

Also also, I see what you mean about hostname -s not persisting after
restarting.

Gary: That's how my /etc/hosts looks too.
I ask because this address is normally entered into /etc/hosts as well,
unless of course DHCP is creating the assignment (different address every
time).

I suppose I should mention that my address is assigned by DHCP, so if I
understand correctly, it wouldn't show up in that file. I'm assuming
that OS X keeps track of the association somewhere else (and I'm
further assuming that this is handled by Bonjour/Zeroconf?).
By the way, the "::1 localhost" syntax is quite alien from a *nix
perspective. Hard to say what it means.

Yeah, that confused me at first as well. I looked into it and it's for
IPv6 compatibility.
 
G

gwtmp01

Do you mean it has an assigned address as well as being defined as
hostname?
I ask because this address is normally entered into /etc/hosts as
well,
unless of course DHCP is creating the assignment (different address
every
time).

DHCP assignment from my firewall/router.
By the way, the "::1 localhost" syntax is quite alien from a *nix
perspective. Hard to say what it means.

::1 is the IPv6 loopback address. Mac OS X has full support for IPv6.


Gary Wright
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top