Portable FQDM in Ruby?

I am trying to get the fully qualified domain name of a machine in a
way that is posrtable in Ruby.

My very first shot was something like

puts %x{hostname} + ‘.’ + %x{domainname}

but that only works on Unix, and I need it portable across PCs too.

My next shot was:

Socket.gethostname

but this returned a nostname that was not fully qualified, which is
fair enough

Socket.gethostbyname(IPSocket.getaddress(host))

didn’t return a fully qualified name either.

Is there a generalised way to do this, or is the assumption that
this is possible for all hosts on the internet somehow false? I
know for hosts not on the internet (192.168.0.0/16 [?]) this could
and probably should fail, but…

I’m trying to take advantage of the portability of ruby here, to
avoid lots of ‘case RUBY_PLATFORM …’ code.

    Thank you,
    Hugh

Hugh Sasse Staff Elec Eng wrote:

I am trying to get the fully qualified domain name of a machine in a
way that is posrtable in Ruby.

My very first shot was something like

puts %x{hostname} + ‘.’ + %x{domainname}

but that only works on Unix, and I need it portable across PCs too.

My next shot was:

Socket.gethostname

but this returned a nostname that was not fully qualified, which is
fair enough

Socket.gethostbyname(IPSocket.getaddress(host))

didn’t return a fully qualified name either.

Is there a generalised way to do this, or is the assumption that
this is possible for all hosts on the internet somehow false? I
know for hosts not on the internet (192.168.0.0/16 [?]) this could
and probably should fail, but…

I’m trying to take advantage of the portability of ruby here, to
avoid lots of ‘case RUBY_PLATFORM …’ code.

    Thank you,
    Hugh

Hi Hugh,

The answer is, “I doubt it”.

The info returned from Socket.getaddrinfo (on *nix systems) is the
addrinfo struct information (netdb.h). Specifically, the ai_canonname
char ptr. According to Unix Network Programming Vol I, by Richard
Stevens, “…the ai_canonname member of the first returned structure
points to the canonical name of the host. In terms of the DNS this is
normally the FQDN.” (emphasis mine). The same is likely true for
Windows systems (WSDATA?), but I’m not sure.

Also note that the nodename, from the utsname struct, is even less
reliable (Stevens, p. 250).

Regards,

Dan

Hugh Sasse Staff Elec Eng wrote:

I am trying to get the fully qualified domain name of a machine in a
way that is posrtable in Ruby.
[…]
I’m trying to take advantage of the portability of ruby here, to
avoid lots of ‘case RUBY_PLATFORM …’ code.

    Thank you,
    Hugh

Hi Hugh,

The answer is, “I doubt it”.

The info returned from Socket.getaddrinfo (on *nix systems) is the
addrinfo struct information (netdb.h). Specifically, the ai_canonname
char ptr. According to Unix Network Programming Vol I, by Richard
Stevens, “…the ai_canonname member of the first returned structure
points to the canonical name of the host. In terms of the DNS this is
normally the FQDN.” (emphasis mine). The same is likely true for
Windows systems (WSDATA?), but I’m not sure.

OK. I’ve not really explored DNS in depth yet.

Also note that the nodename, from the utsname struct, is even less
reliable (Stevens, p. 250).

OK. I’ll try another solution that doesn’t try to find this sort of
thing out.

Regards,

Dan

    Thank you,
    Hugh
···

On Wed, 12 Feb 2003, Daniel Berger wrote: