[erlang-questions] reliably figure out hostname

Vlad Dumitrescu vladdu55@REDACTED
Thu Aug 2 10:38:14 CEST 2012


Hi,

On Thu, Aug 2, 2012 at 10:17 AM, Tim Watson <watson.timothy@REDACTED> wrote:
> Any takers for this? I can't be the only person who's had to figure this
> out. The context is a distributed systems testing framework that needs to
> support resolving 'localhost' to a proper host name so the framework can
> become a hidden node and interact with the other erlang nodes It is testing
> against. Having to specify the real host name would make configuring the
> tool across different machines and development environments unpleasantly
> complicated so figuring out the right hostname is a boon in terms of keeping
> the configuration overhead down, but doing this for long names nodes is
> proving highly awkward.

I'm not a guru for this kind of issues, but even looking at Java's
support for this, the docs say

    String java.net.InetAddress.getCanonicalHostName()
        Gets the fully qualified domain name for this IP address. Best
effort method, meaning we may not be able to return the FQDN depending
on the underlying system configuration.

    String java.net.InetAddress.getHostName()
        Gets the host name for this IP address.
        If this InetAddress was created with a host name, this host
name will be remembered and returned; otherwise, a reverse name lookup
will be performed and the result will be returned based on the system
configured name lookup service. If a lookup of the name service is
required, call getCanonicalHostName.

So it depends on how the system is configured...

regards,
Vlad


> Can anyone suggest a good portable solution?
>
> On 31 Jul 2012, at 13:43, Tim Watson <watson.timothy@REDACTED> wrote:
>
> Is there a way to calculate the hostname reliably across platforms in
> Erlang? I have a non-distributed node that I wish to become a distributed
> node. Normally I call net_kernel:start([Name, shortnames]) and this is just
> fine. It also works with [Name, longnames] *sometimes and on some systems* -
> but other times it pukes. I've tried looking in the 'domain' or 'search'
> entries from inet:get_rc/0 but these are not always populated, even when dns
> config is clearly in place. I've also tried using 'inet_db:get_searchlist/0'
> but again, sometimes this returns [[]] but net_kernel:start([foobar,
> longnames]) doesn't work, whereas doing
> net_kernel:start([foobar@REDACTED, longnames]) does.
>
> Am I missing something incredibly obvious here? *is* there actually a simple
> way of determining what the proper fqdn for the machine should be, without
> breaking out to the os? I had even considered doing inet:gethostbyname/1 but
> again, the search domains entry seems to be empty, so I'd assume that -name
> foobar will work whereas in fact, -name foobar@REDACTED is required otherwise
> net_kernel won't start.
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list